summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-09-28 14:12:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-09-28 14:12:38 -0400
commit61a78c71a656593bf4121e624348a990ba5b91da (patch)
treeb92bc2d6dcda325611550168d48b4d07605040d1
parentf7873900f353ff210ef2ef2aa587e39196b8bf5a (diff)
Assign collations in partition bound expressions.
Failure to do this can result in errors during evaluation of the bound expression, as illustrated by the new regression test. Back-patch to v12 where the ability for partition bounds to be expressions was added. Discussion: https://postgr.es/m/CAJV4CdrZ5mKuaEsRSbLf2URQ3h6iMtKD=hik8MaF5WwdmC9uZw@mail.gmail.com
-rw-r--r--src/backend/parser/parse_utilcmd.c3
-rw-r--r--src/test/regress/expected/create_table.out7
-rw-r--r--src/test/regress/sql/create_table.sql8
3 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 7b5502a06df..6b59538b138 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -4239,7 +4239,10 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
/* Simplify the expression, in case we had a coercion */
if (!IsA(value, Const))
+ {
+ assign_expr_collations(pstate, value);
value = (Node *) expression_planner((Expr *) value);
+ }
/*
* transformExpr() should have already rejected column references,
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out
index 1c72f23bc93..9089b013b7f 100644
--- a/src/test/regress/expected/create_table.out
+++ b/src/test/regress/expected/create_table.out
@@ -986,6 +986,13 @@ DETAIL: Failing row contains (1, null).
Partition of: parted_notnull_inh_test FOR VALUES IN (1)
drop table parted_notnull_inh_test;
+-- check that collations are assigned in partition bound expressions
+create table parted_boolean_col (a bool, b text) partition by list(a);
+create table parted_boolean_less partition of parted_boolean_col
+ for values in ('foo' < 'bar');
+create table parted_boolean_greater partition of parted_boolean_col
+ for values in ('foo' > 'bar');
+drop table parted_boolean_col;
-- check for a conflicting COLLATE clause
create table parted_collate_must_match (a text collate "C", b text collate "C")
partition by range (a);
diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql
index 9b1adcb8add..ad55a24a7bf 100644
--- a/src/test/regress/sql/create_table.sql
+++ b/src/test/regress/sql/create_table.sql
@@ -802,6 +802,14 @@ insert into parted_notnull_inh_test (b) values (null);
\d parted_notnull_inh_test1
drop table parted_notnull_inh_test;
+-- check that collations are assigned in partition bound expressions
+create table parted_boolean_col (a bool, b text) partition by list(a);
+create table parted_boolean_less partition of parted_boolean_col
+ for values in ('foo' < 'bar');
+create table parted_boolean_greater partition of parted_boolean_col
+ for values in ('foo' > 'bar');
+drop table parted_boolean_col;
+
-- check for a conflicting COLLATE clause
create table parted_collate_must_match (a text collate "C", b text collate "C")
partition by range (a);