Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8457d0b

Browse files
committed
docs: document behavior of CHAR() comparisons with chars < space
Space trimming rather than space-padding causes unusual behavior, whichmight not be standards-compliant.Also remove recently-added now-redundant C comment.
1 parent6615e77 commit8457d0b

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,13 @@ SELECT '52093.89'::money::numeric::float8;
10781078
<para>
10791079
Values of type <type>character</type> are physically padded
10801080
with spaces to the specified width <replaceable>n</>, and are
1081-
stored and displayed that way. However, the padding spaces are
1082-
treated as semantically insignificant. Trailing spaces are
1083-
disregarded when comparing two values of type <type>character</type>,
1084-
and they will be removed when converting a <type>character</type> value
1081+
stored and displayed that way. However, trailing spaces are treated as
1082+
semantically insignificant and disregarded when comparing two values
1083+
of type <type>character</type>. In collations where whitespace
1084+
is significant, this behavior can produce unexpected results,
1085+
e.g. <command>SELECT 'a '::CHAR(2) collate "C" < 'a\n'::CHAR(2)
1086+
returns true.
1087+
Trailing spaces are removed when converting a <type>character</type> value
10851088
to one of the other string types. Note that trailing spaces
10861089
<emphasis>are</> semantically significant in
10871090
<type>character varying</type> and <type>text</type> values, and

‎src/backend/utils/adt/varchar.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,6 @@ bpcharcmp(PG_FUNCTION_ARGS)
846846
len2;
847847
intcmp;
848848

849-
/*
850-
* Trimming trailing spaces off of both strings can cause a string
851-
* with a character less than a space to compare greater than a
852-
* space-extended string, e.g. this returns false:
853-
*SELECT E'ab\n'::CHAR(10) < E'ab '::CHAR(10);
854-
* even though '\n' is less than the space if CHAR(10) was
855-
* space-extended. The correct solution would be to trim only
856-
* the longer string to be the same length of the shorter, if
857-
* possible, then do the comparison. However, changing this
858-
* might break existing indexes, breaking binary upgrades.
859-
* For details, see http://www.postgresql.org/message-id/CAK+WP1xdmyswEehMuetNztM4H199Z1w9KWRHVMKzyyFM+hV=zA@mail.gmail.com
860-
*/
861849
len1=bcTruelen(arg1);
862850
len2=bcTruelen(arg2);
863851

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp