Skip to content

Commit 72647ac

Browse files
committed
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
1 parent 2dfa3fe commit 72647ac

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/backend/parser/parse_utilcmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,7 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
42094209
*/
42104210
if (!IsA(value, Const))
42114211
{
4212+
assign_expr_collations(pstate, value);
42124213
value = (Node *) expression_planner((Expr *) value);
42134214
value = (Node *) evaluate_expr((Expr *) value, colType, colTypmod,
42144215
partCollation);

src/test/regress/expected/create_table.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,13 @@ DETAIL: Failing row contains (1, null).
10141014
Partition of: parted_notnull_inh_test FOR VALUES IN (1)
10151015

10161016
drop table parted_notnull_inh_test;
1017+
-- check that collations are assigned in partition bound expressions
1018+
create table parted_boolean_col (a bool, b text) partition by list(a);
1019+
create table parted_boolean_less partition of parted_boolean_col
1020+
for values in ('foo' < 'bar');
1021+
create table parted_boolean_greater partition of parted_boolean_col
1022+
for values in ('foo' > 'bar');
1023+
drop table parted_boolean_col;
10171024
-- check for a conflicting COLLATE clause
10181025
create table parted_collate_must_match (a text collate "C", b text collate "C")
10191026
partition by range (a);

src/test/regress/sql/create_table.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,14 @@ insert into parted_notnull_inh_test (b) values (null);
801801
\d parted_notnull_inh_test1
802802
drop table parted_notnull_inh_test;
803803

804+
-- check that collations are assigned in partition bound expressions
805+
create table parted_boolean_col (a bool, b text) partition by list(a);
806+
create table parted_boolean_less partition of parted_boolean_col
807+
for values in ('foo' < 'bar');
808+
create table parted_boolean_greater partition of parted_boolean_col
809+
for values in ('foo' > 'bar');
810+
drop table parted_boolean_col;
811+
804812
-- check for a conflicting COLLATE clause
805813
create table parted_collate_must_match (a text collate "C", b text collate "C")
806814
partition by range (a);

0 commit comments

Comments
 (0)