Skip to content

Commit d8d4298

Browse files
committed
Fix collations when we call transformWhereClause from outside the parser.
Previous patches took care of assorted places that call transformExpr from outside the main parser, but I overlooked the fact that some places use transformWhereClause as a shortcut for transformExpr + coerce_to_boolean. In particular this broke collation-sensitive index WHERE clauses, as per report from Thom Brown. Trigger WHEN and rule WHERE clauses too. I'm not forcing initdb for this fix, but any affected indexes, triggers, or rules will need to be dropped and recreated.
1 parent 2594cf0 commit d8d4298

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/backend/commands/trigger.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "optimizer/clauses.h"
3737
#include "optimizer/var.h"
3838
#include "parser/parse_clause.h"
39+
#include "parser/parse_collate.h"
3940
#include "parser/parse_func.h"
4041
#include "parser/parse_relation.h"
4142
#include "parser/parsetree.h"
@@ -282,6 +283,8 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
282283
whenClause = transformWhereClause(pstate,
283284
copyObject(stmt->whenClause),
284285
"WHEN");
286+
/* we have to fix its collations too */
287+
assign_expr_collations(pstate, whenClause);
285288

286289
/*
287290
* No subplans or aggregates, please

src/backend/parser/parse_utilcmd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,13 @@ transformIndexStmt(IndexStmt *stmt, const char *queryString)
18291829

18301830
/* take care of the where clause */
18311831
if (stmt->whereClause)
1832+
{
18321833
stmt->whereClause = transformWhereClause(pstate,
18331834
stmt->whereClause,
18341835
"WHERE");
1836+
/* we have to fix its collations too */
1837+
assign_expr_collations(pstate, stmt->whereClause);
1838+
}
18351839

18361840
/* take care of any index expressions */
18371841
foreach(l, stmt->indexParams)
@@ -1959,6 +1963,8 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
19591963
*whereClause = transformWhereClause(pstate,
19601964
(Node *) copyObject(stmt->whereClause),
19611965
"WHERE");
1966+
/* we have to fix its collations too */
1967+
assign_expr_collations(pstate, *whereClause);
19621968

19631969
if (list_length(pstate->p_rtable) != 2) /* naughty, naughty... */
19641970
ereport(ERROR,

0 commit comments

Comments
 (0)