]> granicus.if.org Git - postgresql/commitdiff
Add assign_expr_collations() to CreatePolicy() and AlterPolicy().
authorJoe Conway <mail@joeconway.com>
Sat, 11 Jul 2015 21:19:31 +0000 (14:19 -0700)
committerJoe Conway <mail@joeconway.com>
Sat, 11 Jul 2015 21:19:31 +0000 (14:19 -0700)
As noted by Noah Misch, CreatePolicy() and AlterPolicy() omit to call
assign_expr_collations() on the node trees. Fix the omission and add
his test case to the rowsecurity regression test.

src/backend/commands/policy.c
src/test/regress/expected/rowsecurity.out
src/test/regress/sql/rowsecurity.sql

index 11efc9f30f1448a5112d45187302dc826d5ad13a..72329834a3137befdcaaeb25448855b47110b933 100644 (file)
@@ -538,6 +538,10 @@ CreatePolicy(CreatePolicyStmt *stmt)
                                                                                   EXPR_KIND_WHERE,
                                                                                   "POLICY");
 
+       /* Fix up collation information */
+       assign_expr_collations(qual_pstate, qual);
+       assign_expr_collations(with_check_pstate, with_check_qual);
+
        /* Open pg_policy catalog */
        pg_policy_rel = heap_open(PolicyRelationId, RowExclusiveLock);
 
@@ -681,6 +685,9 @@ AlterPolicy(AlterPolicyStmt *stmt)
                                                                        EXPR_KIND_WHERE,
                                                                        "POLICY");
 
+               /* Fix up collation information */
+               assign_expr_collations(qual_pstate, qual);
+
                qual_parse_rtable = qual_pstate->p_rtable;
                free_parsestate(qual_pstate);
        }
@@ -701,6 +708,9 @@ AlterPolicy(AlterPolicyStmt *stmt)
                                                                                           EXPR_KIND_WHERE,
                                                                                           "POLICY");
 
+               /* Fix up collation information */
+               assign_expr_collations(with_check_pstate, with_check_qual);
+
                with_check_parse_rtable = with_check_pstate->p_rtable;
                free_parsestate(with_check_pstate);
        }
index 4073c1beea511e0e8b090e36ded3163c4d31eff6..eabfd932de9b2103646ea508b81085e86d8da830 100644 (file)
@@ -2730,6 +2730,27 @@ ERROR:  permission denied for relation copy_t
 RESET SESSION AUTHORIZATION;
 DROP TABLE copy_t;
 --
+-- Collation support
+--
+BEGIN;
+SET row_security = force;
+CREATE TABLE coll_t (c) AS VALUES ('bar'::text);
+CREATE POLICY coll_p ON coll_t USING (c < ('foo'::text COLLATE "C"));
+ALTER TABLE coll_t ENABLE ROW LEVEL SECURITY;
+SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE polrelid = 'coll_t'::regclass;
+   inputcollid    
+------------------
+ inputcollid 950 
+(1 row)
+
+SELECT * FROM coll_t;
+  c  
+-----
+ bar
+(1 row)
+
+ROLLBACK;
+--
 -- Clean up objects
 --
 RESET SESSION AUTHORIZATION;
index fdd9b892ce6a8cf5b608709754600dc40c452659..782824acfdae70417c5a25ab14c04855ca90e066 100644 (file)
@@ -1087,6 +1087,18 @@ COPY copy_t FROM STDIN; --fail - permission denied.
 RESET SESSION AUTHORIZATION;
 DROP TABLE copy_t;
 
+--
+-- Collation support
+--
+BEGIN;
+SET row_security = force;
+CREATE TABLE coll_t (c) AS VALUES ('bar'::text);
+CREATE POLICY coll_p ON coll_t USING (c < ('foo'::text COLLATE "C"));
+ALTER TABLE coll_t ENABLE ROW LEVEL SECURITY;
+SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE polrelid = 'coll_t'::regclass;
+SELECT * FROM coll_t;
+ROLLBACK;
+
 --
 -- Clean up objects
 --