File tree Expand file tree Collapse file tree 3 files changed +87
-2
lines changed Expand file tree Collapse file tree 3 files changed +87
-2
lines changed Original file line number Diff line number Diff line change @@ -764,7 +764,6 @@ inheritance_planner(PlannerInfo *root)
764
764
subroot .parse = (Query * )
765
765
adjust_appendrel_attrs ((Node * ) parse ,
766
766
appinfo );
767
- subroot .init_plans = NIL ;
768
767
subroot .hasInheritedTarget = true;
769
768
/* We needn't modify the child's append_rel_list */
770
769
/* There shouldn't be any OJ info to translate, as yet */
@@ -789,7 +788,7 @@ inheritance_planner(PlannerInfo *root)
789
788
subplans = lappend (subplans , subplan );
790
789
791
790
/* Make sure any initplans from this rel get into the outer list */
792
- root -> init_plans = list_concat ( root -> init_plans , subroot .init_plans ) ;
791
+ root -> init_plans = subroot .init_plans ;
793
792
794
793
/* Build list of target-relation RT indexes */
795
794
resultRelations = lappend_int (resultRelations , appinfo -> child_relid );
Original file line number Diff line number Diff line change @@ -1800,6 +1800,62 @@ SELECT * FROM y;
1800
1800
1801
1801
DROP TRIGGER y_trig ON y;
1802
1802
DROP FUNCTION y_trigger();
1803
+ -- WITH attached to inherited UPDATE or DELETE
1804
+ CREATE TEMP TABLE parent ( id int, val text );
1805
+ CREATE TEMP TABLE child1 ( ) INHERITS ( parent );
1806
+ CREATE TEMP TABLE child2 ( ) INHERITS ( parent );
1807
+ INSERT INTO parent VALUES ( 1, 'p1' );
1808
+ INSERT INTO child1 VALUES ( 11, 'c11' ),( 12, 'c12' );
1809
+ INSERT INTO child2 VALUES ( 23, 'c21' ),( 24, 'c22' );
1810
+ WITH rcte AS ( SELECT sum(id) AS totalid FROM parent )
1811
+ UPDATE parent SET id = id + totalid FROM rcte;
1812
+ SELECT * FROM parent;
1813
+ id | val
1814
+ ----+-----
1815
+ 72 | p1
1816
+ 82 | c11
1817
+ 83 | c12
1818
+ 94 | c21
1819
+ 95 | c22
1820
+ (5 rows)
1821
+
1822
+ WITH wcte AS ( INSERT INTO child1 VALUES ( 42, 'new' ) RETURNING id AS newid )
1823
+ UPDATE parent SET id = id + newid FROM wcte;
1824
+ SELECT * FROM parent;
1825
+ id | val
1826
+ -----+-----
1827
+ 114 | p1
1828
+ 42 | new
1829
+ 124 | c11
1830
+ 125 | c12
1831
+ 136 | c21
1832
+ 137 | c22
1833
+ (6 rows)
1834
+
1835
+ WITH rcte AS ( SELECT max(id) AS maxid FROM parent )
1836
+ DELETE FROM parent USING rcte WHERE id = maxid;
1837
+ SELECT * FROM parent;
1838
+ id | val
1839
+ -----+-----
1840
+ 114 | p1
1841
+ 42 | new
1842
+ 124 | c11
1843
+ 125 | c12
1844
+ 136 | c21
1845
+ (5 rows)
1846
+
1847
+ WITH wcte AS ( INSERT INTO child2 VALUES ( 42, 'new2' ) RETURNING id AS newid )
1848
+ DELETE FROM parent USING wcte WHERE id = newid;
1849
+ SELECT * FROM parent;
1850
+ id | val
1851
+ -----+------
1852
+ 114 | p1
1853
+ 124 | c11
1854
+ 125 | c12
1855
+ 136 | c21
1856
+ 42 | new2
1857
+ (5 rows)
1858
+
1803
1859
-- error cases
1804
1860
-- data-modifying WITH tries to use its own output
1805
1861
WITH RECURSIVE t AS (
Original file line number Diff line number Diff line change @@ -761,6 +761,36 @@ SELECT * FROM y;
761
761
DROP TRIGGER y_trig ON y;
762
762
DROP FUNCTION y_trigger();
763
763
764
+ -- WITH attached to inherited UPDATE or DELETE
765
+
766
+ CREATE TEMP TABLE parent ( id int , val text );
767
+ CREATE TEMP TABLE child1 ( ) INHERITS ( parent );
768
+ CREATE TEMP TABLE child2 ( ) INHERITS ( parent );
769
+
770
+ INSERT INTO parent VALUES ( 1 , ' p1' );
771
+ INSERT INTO child1 VALUES ( 11 , ' c11' ),( 12 , ' c12' );
772
+ INSERT INTO child2 VALUES ( 23 , ' c21' ),( 24 , ' c22' );
773
+
774
+ WITH rcte AS ( SELECT sum (id) AS totalid FROM parent )
775
+ UPDATE parent SET id = id + totalid FROM rcte;
776
+
777
+ SELECT * FROM parent;
778
+
779
+ WITH wcte AS ( INSERT INTO child1 VALUES ( 42 , ' new' ) RETURNING id AS newid )
780
+ UPDATE parent SET id = id + newid FROM wcte;
781
+
782
+ SELECT * FROM parent;
783
+
784
+ WITH rcte AS ( SELECT max (id) AS maxid FROM parent )
785
+ DELETE FROM parent USING rcte WHERE id = maxid;
786
+
787
+ SELECT * FROM parent;
788
+
789
+ WITH wcte AS ( INSERT INTO child2 VALUES ( 42 , ' new2' ) RETURNING id AS newid )
790
+ DELETE FROM parent USING wcte WHERE id = newid;
791
+
792
+ SELECT * FROM parent;
793
+
764
794
-- error cases
765
795
766
796
-- data-modifying WITH tries to use its own output
You can’t perform that action at this time.
0 commit comments