aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/varchar.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-02-13 21:45:57 -0500
committerBruce Momjian <bruce@momjian.us>2014-02-13 21:46:03 -0500
commit9c57d11fca3b87daa741151f75085e2554ee310f (patch)
treefa758dff39785f5960a3656b72384253ccfca3eb /src/backend/utils/adt/varchar.c
parentb8f00a46bc4ae77c09f4564f3b3c675fb9e51974 (diff)
downloadpostgresql-9c57d11fca3b87daa741151f75085e2554ee310f.tar.gz
postgresql-9c57d11fca3b87daa741151f75085e2554ee310f.zip
Add C comment about problems with CHAR() space trimming
Diffstat (limited to 'src/backend/utils/adt/varchar.c')
-rw-r--r--src/backend/utils/adt/varchar.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 502ca44e04a..284b5d13093 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -846,6 +846,18 @@ 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);