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

Commit 61a78c7

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 f787390 commit 61a78c7

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
@@ -4239,7 +4239,10 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
42394239

42404240
/* Simplify the expression, in case we had a coercion */
42414241
if (!IsA(value, Const))
4242+
{
4243+
assign_expr_collations(pstate, value);
42424244
value = (Node *) expression_planner((Expr *) value);
4245+
}
42434246

42444247
/*
42454248
* 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
@@ -986,6 +986,13 @@ DETAIL: Failing row contains (1, null).
986986
Partition of: parted_notnull_inh_test FOR VALUES IN (1)
987987

988988
drop table parted_notnull_inh_test;
989+
-- check that collations are assigned in partition bound expressions
990+
create table parted_boolean_col (a bool, b text) partition by list(a);
991+
create table parted_boolean_less partition of parted_boolean_col
992+
for values in ('foo' < 'bar');
993+
create table parted_boolean_greater partition of parted_boolean_col
994+
for values in ('foo' > 'bar');
995+
drop table parted_boolean_col;
989996
-- check for a conflicting COLLATE clause
990997
create table parted_collate_must_match (a text collate "C", b text collate "C")
991998
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
@@ -802,6 +802,14 @@ insert into parted_notnull_inh_test (b) values (null);
802802
\d parted_notnull_inh_test1
803803
drop table parted_notnull_inh_test;
804804

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

0 commit comments

Comments
 (0)