Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 29f20db

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 bda3273 commit 29f20db

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/backend/parser/parse_utilcmd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,7 +4197,10 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
41974197

41984198
/* Simplify the expression, in case we had a coercion */
41994199
if (!IsA(value, Const))
4200+
{
4201+
assign_expr_collations(pstate, value);
42004202
value = (Node *) expression_planner((Expr *) value);
4203+
}
42014204

42024205
/*
42034206
* transformExpr() should have already rejected column references,

src/test/regress/expected/create_table.out

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

939939
drop table parted_notnull_inh_test;
940+
-- check that collations are assigned in partition bound expressions
941+
create table parted_boolean_col (a bool, b text) partition by list(a);
942+
create table parted_boolean_less partition of parted_boolean_col
943+
for values in ('foo' < 'bar');
944+
create table parted_boolean_greater partition of parted_boolean_col
945+
for values in ('foo' > 'bar');
946+
drop table parted_boolean_col;
940947
-- check for a conflicting COLLATE clause
941948
create table parted_collate_must_match (a text collate "C", b text collate "C")
942949
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
@@ -769,6 +769,14 @@ insert into parted_notnull_inh_test (b) values (null);
769769
\d parted_notnull_inh_test1
770770
drop table parted_notnull_inh_test;
771771

772+
-- check that collations are assigned in partition bound expressions
773+
create table parted_boolean_col (a bool, b text) partition by list(a);
774+
create table parted_boolean_less partition of parted_boolean_col
775+
for values in ('foo' < 'bar');
776+
create table parted_boolean_greater partition of parted_boolean_col
777+
for values in ('foo' > 'bar');
778+
drop table parted_boolean_col;
779+
772780
-- check for a conflicting COLLATE clause
773781
create table parted_collate_must_match (a text collate "C", b text collate "C")
774782
partition by range (a);

0 commit comments

Comments
 (0)