]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Assign collations in partition bound expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Sep 2020 18:12:38 +0000 (14:12 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 28 Sep 2020 18:12:38 +0000 (14:12 -0400)
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

src/backend/parser/parse_utilcmd.c
src/test/regress/expected/create_table.out
src/test/regress/sql/create_table.sql

index e54d8279917eec025e44fe0f413068d9c63f4ac3..0ceea41d1b6d713f3591e9f59bf9b36363d7fd31 100644 (file)
@@ -4197,7 +4197,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,
index 2753778197a22084761446f63973bc57ae503796..96361e36611c3bf0d44a3bc2b2e2d15ddea1b2bd 100644 (file)
@@ -937,6 +937,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);
index 97074ff1c11ae4516d3e14edb02f1d5d81497bd8..c8f40b94c24c52ae725b22efc9307c5141a100c6 100644 (file)
@@ -769,6 +769,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);