diff options
author | Stephen Frost <sfrost@snowman.net> | 2014-09-22 20:12:51 -0400 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2014-09-22 20:12:51 -0400 |
commit | 6ef8c658af2127f4e62cb24feade8b465c9e2fea (patch) | |
tree | 1e188a2dd608da5969e3ed7ff514f58820aa94c0 /src | |
parent | 6ba4ecbf477e0b25dd7bde1b0c4e07fc2da19348 (diff) | |
download | postgresql-6ef8c658af2127f4e62cb24feade8b465c9e2fea.tar.gz postgresql-6ef8c658af2127f4e62cb24feade8b465c9e2fea.zip |
Process withCheckOption exprs in setrefs.c
While withCheckOption exprs had been handled in many cases by
happenstance, they need to be handled during set_plan_references and
more specifically down in set_plan_refs for ModifyTable plan nodes.
This is to ensure that the opfuncid's are set for operators referenced
in the withCheckOption exprs.
Identified as an issue by Thom Brown
Patch by Dean Rasheed
Back-patch to 9.4, where withCheckOption was introduced.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/plan/setrefs.c | 3 | ||||
-rw-r--r-- | src/test/regress/expected/updatable_views.out | 20 | ||||
-rw-r--r-- | src/test/regress/sql/updatable_views.sql | 19 |
3 files changed, 42 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 5bf84c1a214..9ddc8adcf98 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -696,6 +696,9 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) Assert(splan->plan.targetlist == NIL); Assert(splan->plan.qual == NIL); + splan->withCheckOptionLists = + fix_scan_list(root, splan->withCheckOptionLists, rtoffset); + if (splan->returningLists) { List *newRL = NIL; diff --git a/src/test/regress/expected/updatable_views.out b/src/test/regress/expected/updatable_views.out index 6a359251695..8a81251288f 100644 --- a/src/test/regress/expected/updatable_views.out +++ b/src/test/regress/expected/updatable_views.out @@ -1567,6 +1567,26 @@ NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to view rw_view1 drop cascades to view rw_view2 drop cascades to view rw_view3 +-- WITH CHECK OPTION with scalar array ops +CREATE TABLE base_tbl (a int, b int[]); +CREATE VIEW rw_view1 AS SELECT * FROM base_tbl WHERE a = ANY (b) + WITH CHECK OPTION; +INSERT INTO rw_view1 VALUES (1, ARRAY[1,2,3]); -- ok +INSERT INTO rw_view1 VALUES (10, ARRAY[4,5]); -- should fail +ERROR: new row violates WITH CHECK OPTION for "rw_view1" +DETAIL: Failing row contains (10, {4,5}). +UPDATE rw_view1 SET b[2] = -b[2] WHERE a = 1; -- ok +UPDATE rw_view1 SET b[1] = -b[1] WHERE a = 1; -- should fail +ERROR: new row violates WITH CHECK OPTION for "rw_view1" +DETAIL: Failing row contains (1, {-1,-2,3}). +PREPARE ins(int, int[]) AS INSERT INTO rw_view1 VALUES($1, $2); +EXECUTE ins(2, ARRAY[1,2,3]); -- ok +EXECUTE ins(10, ARRAY[4,5]); -- should fail +ERROR: new row violates WITH CHECK OPTION for "rw_view1" +DETAIL: Failing row contains (10, {4,5}). +DEALLOCATE PREPARE ins; +DROP TABLE base_tbl CASCADE; +NOTICE: drop cascades to view rw_view1 -- WITH CHECK OPTION with subquery CREATE TABLE base_tbl (a int); CREATE TABLE ref_tbl (a int PRIMARY KEY); diff --git a/src/test/regress/sql/updatable_views.sql b/src/test/regress/sql/updatable_views.sql index c072fca6be2..60c7e292212 100644 --- a/src/test/regress/sql/updatable_views.sql +++ b/src/test/regress/sql/updatable_views.sql @@ -707,6 +707,25 @@ INSERT INTO rw_view3 VALUES (3); -- ok DROP TABLE base_tbl CASCADE; +-- WITH CHECK OPTION with scalar array ops + +CREATE TABLE base_tbl (a int, b int[]); +CREATE VIEW rw_view1 AS SELECT * FROM base_tbl WHERE a = ANY (b) + WITH CHECK OPTION; + +INSERT INTO rw_view1 VALUES (1, ARRAY[1,2,3]); -- ok +INSERT INTO rw_view1 VALUES (10, ARRAY[4,5]); -- should fail + +UPDATE rw_view1 SET b[2] = -b[2] WHERE a = 1; -- ok +UPDATE rw_view1 SET b[1] = -b[1] WHERE a = 1; -- should fail + +PREPARE ins(int, int[]) AS INSERT INTO rw_view1 VALUES($1, $2); +EXECUTE ins(2, ARRAY[1,2,3]); -- ok +EXECUTE ins(10, ARRAY[4,5]); -- should fail +DEALLOCATE PREPARE ins; + +DROP TABLE base_tbl CASCADE; + -- WITH CHECK OPTION with subquery CREATE TABLE base_tbl (a int); |