Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ef8c65

Browse files
committed
Process withCheckOption exprs in setrefs.c
While withCheckOption exprs had been handled in many cases byhappenstance, they need to be handled during set_plan_references andmore specifically down in set_plan_refs for ModifyTable plan nodes.This is to ensure that the opfuncid's are set for operators referencedin the withCheckOption exprs.Identified as an issue by Thom BrownPatch by Dean RasheedBack-patch to 9.4, where withCheckOption was introduced.
1 parent6ba4ecb commit6ef8c65

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
696696
Assert(splan->plan.targetlist==NIL);
697697
Assert(splan->plan.qual==NIL);
698698

699+
splan->withCheckOptionLists=
700+
fix_scan_list(root,splan->withCheckOptionLists,rtoffset);
701+
699702
if (splan->returningLists)
700703
{
701704
List*newRL=NIL;

‎src/test/regress/expected/updatable_views.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,26 @@ NOTICE: drop cascades to 3 other objects
15671567
DETAIL: drop cascades to view rw_view1
15681568
drop cascades to view rw_view2
15691569
drop cascades to view rw_view3
1570+
-- WITH CHECK OPTION with scalar array ops
1571+
CREATE TABLE base_tbl (a int, b int[]);
1572+
CREATE VIEW rw_view1 AS SELECT * FROM base_tbl WHERE a = ANY (b)
1573+
WITH CHECK OPTION;
1574+
INSERT INTO rw_view1 VALUES (1, ARRAY[1,2,3]); -- ok
1575+
INSERT INTO rw_view1 VALUES (10, ARRAY[4,5]); -- should fail
1576+
ERROR: new row violates WITH CHECK OPTION for "rw_view1"
1577+
DETAIL: Failing row contains (10, {4,5}).
1578+
UPDATE rw_view1 SET b[2] = -b[2] WHERE a = 1; -- ok
1579+
UPDATE rw_view1 SET b[1] = -b[1] WHERE a = 1; -- should fail
1580+
ERROR: new row violates WITH CHECK OPTION for "rw_view1"
1581+
DETAIL: Failing row contains (1, {-1,-2,3}).
1582+
PREPARE ins(int, int[]) AS INSERT INTO rw_view1 VALUES($1, $2);
1583+
EXECUTE ins(2, ARRAY[1,2,3]); -- ok
1584+
EXECUTE ins(10, ARRAY[4,5]); -- should fail
1585+
ERROR: new row violates WITH CHECK OPTION for "rw_view1"
1586+
DETAIL: Failing row contains (10, {4,5}).
1587+
DEALLOCATE PREPARE ins;
1588+
DROP TABLE base_tbl CASCADE;
1589+
NOTICE: drop cascades to view rw_view1
15701590
-- WITH CHECK OPTION with subquery
15711591
CREATE TABLE base_tbl (a int);
15721592
CREATE TABLE ref_tbl (a int PRIMARY KEY);

‎src/test/regress/sql/updatable_views.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,25 @@ INSERT INTO rw_view3 VALUES (3); -- ok
707707

708708
DROPTABLE base_tbl CASCADE;
709709

710+
-- WITH CHECK OPTION with scalar array ops
711+
712+
CREATETABLEbase_tbl (aint, bint[]);
713+
CREATEVIEWrw_view1ASSELECT*FROM base_tblWHERE a= ANY (b)
714+
WITHCHECK OPTION;
715+
716+
INSERT INTO rw_view1VALUES (1, ARRAY[1,2,3]);-- ok
717+
INSERT INTO rw_view1VALUES (10, ARRAY[4,5]);-- should fail
718+
719+
UPDATE rw_view1SET b[2]=-b[2]WHERE a=1;-- ok
720+
UPDATE rw_view1SET b[1]=-b[1]WHERE a=1;-- should fail
721+
722+
PREPARE ins(int,int[])ASINSERT INTO rw_view1VALUES($1, $2);
723+
EXECUTE ins(2, ARRAY[1,2,3]);-- ok
724+
EXECUTE ins(10, ARRAY[4,5]);-- should fail
725+
DEALLOCATE PREPARE ins;
726+
727+
DROPTABLE base_tbl CASCADE;
728+
710729
-- WITH CHECK OPTION with subquery
711730

712731
CREATETABLEbase_tbl (aint);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp