postgresql/contrib/seg
Heikki Linnakangas 0e1f1ed157 seg: Fix seg_out() to preserve the upper boundary's certainty indicator
When printing the upper boundary of a seg interval, seg_out() decided
whether to emit the certainty indicator ('<', '>' or '~') by testing the
upper indicator (u_ext) for '<' and '>', but mistakenly tested the lower
indicator (l_ext) for '~'.  This is a copy-and-paste slip from the
symmetric code that prints the lower boundary a few lines above.

The consequences for valid input were:

  * A '~' on the upper boundary was dropped on output, e.g.
    '1.5 .. ~2.5'::seg printed as '1.5 .. 2.5'.

  * When the lower boundary carried '~' but the upper boundary had no
    indicator, the wrong test matched and sprintf(p, "%c", seg->u_ext)
    wrote a NUL byte (u_ext == '\0'), which truncated the result string
    and silently lost the entire upper boundary, e.g.
    '~6.5 .. 8.5'::seg printed as '~6.5 .. '.

Certainty indicators are documented to be preserved on output (they are
ignored by the operators, but kept as comments), so this broke the
input/output round-trip for the affected values.

The bug has existed since seg was added.  It went unnoticed because the
existing regression tests only exercised certainty indicators on
single-point segs, which are printed by a different branch of seg_out().
Add tests that place indicators on both boundaries of an interval.

Author: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAON2xHPYeRRCEVAv8XfE18KsEsEHCiYcJ5fOsoxFuMEfpxF1=g@mail.gmail.com
Backpatch-through: 14
2026-06-11 12:33:48 +03:00
..
data Modify the float4 datatype to be pass-by-val. Along the way, remove the last 2008-04-18 18:43:09 +00:00
expected seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:33:48 +03:00
sql seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:33:48 +03:00
.gitignore Build all Flex files standalone 2022-09-04 12:09:01 +07:00
Makefile Use generateClonedIndexStmt to propagate CREATE INDEX to partitions. 2024-10-05 14:46:44 -04:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
seg--1.0--1.1.sql Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
seg--1.1--1.2.sql Update contrib/seg for new scalarlesel/scalargesel selectivity functions. 2017-09-13 11:54:55 -04:00
seg--1.1.sql Update extensions with GIN/GIST support for parallel query. 2016-06-14 13:34:37 -04:00
seg--1.2--1.3.sql Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
seg--1.3--1.4.sql Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
seg-validate.pl Update copyright for 2026 2026-01-01 13:24:10 -05:00
seg.c seg: Fix seg_out() to preserve the upper boundary's certainty indicator 2026-06-11 12:33:48 +03:00
seg.control Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
segdata.h Allow redeclaration of typedef yyscan_t 2025-09-12 08:16:00 +02:00
segparse.y seg: pure parser and reentrant scanner 2024-12-18 08:47:53 +01:00
segscan.l Partial pgindent of .l and .y files 2024-12-25 17:55:42 +01:00
sort-segments.pl Update copyright for 2026 2026-01-01 13:24:10 -05:00