diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 00ccbe1bb5..ebcadf617a 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1078,10 +1078,13 @@ SELECT '52093.89'::money::numeric::float8; Values of type character are physically padded with spaces to the specified width n, and are - stored and displayed that way. However, the padding spaces are - treated as semantically insignificant. Trailing spaces are - disregarded when comparing two values of type character, - and they will be removed when converting a character value + stored and displayed that way. However, trailing spaces are treated as + semantically insignificant and disregarded when comparing two values + of type character. In collations where whitespace + is significant, this behavior can produce unexpected results, + e.g. SELECT 'a '::CHAR(2) collate "C" < 'a\n'::CHAR(2) + returns true. + Trailing spaces are removed when converting a character value to one of the other string types. Note that trailing spaces are semantically significant in character varying and text values, and diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 284b5d1309..502ca44e04 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -846,18 +846,6 @@ bpcharcmp(PG_FUNCTION_ARGS) len2; int cmp; - /* - * Trimming trailing spaces off of both strings can cause a string - * with a character less than a space to compare greater than a - * space-extended string, e.g. this returns false: - * SELECT E'ab\n'::CHAR(10) < E'ab '::CHAR(10); - * even though '\n' is less than the space if CHAR(10) was - * space-extended. The correct solution would be to trim only - * the longer string to be the same length of the shorter, if - * possible, then do the comparison. However, changing this - * might break existing indexes, breaking binary upgrades. - * For details, see http://www.postgresql.org/message-id/CAK+WP1xdmyswEehMuetNztM4H199Z1w9KWRHVMKzyyFM+hV=zA@mail.gmail.com - */ len1 = bcTruelen(arg1); len2 = bcTruelen(arg2);