summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2020-09-28 18:12:38 +0000
committerTom Lane2020-09-28 18:12:38 +0000
commit72647ac3bf0f11732483eac2cd9b5cf4972f2e1f (patch)
tree93ec07545e20e4e33f77e5b2b0e63c5fe0c13d8c
parent2dfa3fea88bc951d0812a18649d801f07964c9b9 (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.c1
-rw-r--r--src/test/regress/expected/create_table.out7
-rw-r--r--src/test/regress/sql/create_table.sql8
3 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 6d2f36da2d..0dc03dd984 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -4209,6 +4209,7 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
*/
if (!IsA(value, Const))
{
+ assign_expr_collations(pstate, value);
value = (Node *) expression_planner((Expr *) value);
value = (Node *) evaluate_expr((Expr *) value, colType, colTypmod,
partCollation);
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out
index 8ed4fae934..45f4a73447 100644
--- a/src/test/regress/expected/create_table.out
+++ b/src/test/regress/expected/create_table.out
@@ -1014,6 +1014,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 e6f0188a51..22602aae5d 100644
--- a/src/test/regress/sql/create_table.sql
+++ b/src/test/regress/sql/create_table.sql
@@ -801,6 +801,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);