On 07/03/2015 10:03 AM, Noah Misch wrote: > (1) CreatePolicy() and AlterPolicy() omit to call assign_expr_collations() on > the node trees. Test case: > > begin; > set row_security = force; > create table t (c) as values ('bar'::text); > create policy p on t using (c < ('foo'::text COLLATE "C")); > alter table t enable row level security; > table pg_policy; -- note ":inputcollid 0" > select * from t; -- ERROR: could not determine which collation ... > rollback;
The attached fixes this issue for me, but I am unsure whether we really need/want the regression test. Given the recent push to increase test coverage maybe so. Any objections? Joe
diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c index 11efc9f..7232983 100644 *** a/src/backend/commands/policy.c --- b/src/backend/commands/policy.c *************** CreatePolicy(CreatePolicyStmt *stmt) *** 538,543 **** --- 538,547 ---- 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); *************** AlterPolicy(AlterPolicyStmt *stmt) *** 681,686 **** --- 685,693 ---- 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); } *************** AlterPolicy(AlterPolicyStmt *stmt) *** 701,706 **** --- 708,716 ---- 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); } diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out index 4073c1b..eabfd93 100644 *** a/src/test/regress/expected/rowsecurity.out --- b/src/test/regress/expected/rowsecurity.out *************** ERROR: permission denied for relation c *** 2730,2735 **** --- 2730,2756 ---- 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; diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql index fdd9b89..782824a 100644 *** a/src/test/regress/sql/rowsecurity.sql --- b/src/test/regress/sql/rowsecurity.sql *************** RESET SESSION AUTHORIZATION; *** 1088,1093 **** --- 1088,1105 ---- 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 -- RESET SESSION AUTHORIZATION;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers