]> granicus.if.org Git - postgresql/commitdiff
Fix collations when we call transformWhereClause from outside the parser.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Apr 2011 06:34:57 +0000 (02:34 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Apr 2011 06:34:57 +0000 (02:34 -0400)
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.

src/backend/commands/trigger.c
src/backend/parser/parse_utilcmd.c

index 0af8a11b0a796f50348144244594cecca4089d59..329d4d95f151e292e509cd0cd5e152ca041097d5 100644 (file)
@@ -36,6 +36,7 @@
 #include "optimizer/clauses.h"
 #include "optimizer/var.h"
 #include "parser/parse_clause.h"
+#include "parser/parse_collate.h"
 #include "parser/parse_func.h"
 #include "parser/parse_relation.h"
 #include "parser/parsetree.h"
@@ -282,6 +283,8 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
                whenClause = transformWhereClause(pstate,
                                                                                  copyObject(stmt->whenClause),
                                                                                  "WHEN");
+               /* we have to fix its collations too */
+               assign_expr_collations(pstate, whenClause);
 
                /*
                 * No subplans or aggregates, please
index fe8d0c4fac1cd4f0c3040b71fe97af162f7f7ef9..b65f5f991cb5502152985ce41a79d1375334220b 100644 (file)
@@ -1829,9 +1829,13 @@ transformIndexStmt(IndexStmt *stmt, const char *queryString)
 
        /* take care of the where clause */
        if (stmt->whereClause)
+       {
                stmt->whereClause = transformWhereClause(pstate,
                                                                                                 stmt->whereClause,
                                                                                                 "WHERE");
+               /* we have to fix its collations too */
+               assign_expr_collations(pstate, stmt->whereClause);
+       }
 
        /* take care of any index expressions */
        foreach(l, stmt->indexParams)
@@ -1959,6 +1963,8 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString,
        *whereClause = transformWhereClause(pstate,
                                                                          (Node *) copyObject(stmt->whereClause),
                                                                                "WHERE");
+       /* we have to fix its collations too */
+       assign_expr_collations(pstate, *whereClause);
 
        if (list_length(pstate->p_rtable) != 2)         /* naughty, naughty... */
                ereport(ERROR,