diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-12 18:00:04 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-12 18:00:04 -0400 |
commit | aea1a3f0ebfcbe17f3ce89cf4cf9bd20828c199e (patch) | |
tree | 64f8b75a9a2f59718460dc820b9055e552aa4006 /src/test | |
parent | 11854dee01e582e83d87fc2b3a5316f2d44852b3 (diff) |
Fix ruleutils.c for domain-over-array cases, too.
Further investigation shows that ruleutils isn't quite up to speed either
for cases where we have a domain-over-array: it needs to be prepared to
look past a CoerceToDomain at the top level of field and element
assignments, else it decompiles them incorrectly. Potentially this would
result in failure to dump/reload a rule, if it looked like the one in the
new test case. (I also added a test for EXPLAIN; that output isn't broken,
but clearly we need more test coverage here.)
Like commit b1cb32fb6, this bug is reachable in cases we already support,
so back-patch all the way.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/domain.out | 42 | ||||
-rw-r--r-- | src/test/regress/sql/domain.sql | 11 |
2 files changed, 45 insertions, 8 deletions
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out index 0385757ad7a..d2f9730d66e 100644 --- a/src/test/regress/expected/domain.out +++ b/src/test/regress/expected/domain.out @@ -266,20 +266,48 @@ insert into dcomptable (d1[1].r, d1[1].i) values(100, 99); -- fail ERROR: value for domain dcomptypea violates check constraint "c1" update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0; -- fail ERROR: value for domain dcomptypea violates check constraint "c1" -update dcomptable set d1[1].r = d1[1].r - 1 where d1[1].i > 0; +update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; select * from dcomptable; d1 -------------------- {"(11,)","(,)"} {"(99,)"} - {"(1,2)","(,)"} - {"(3,4)","(6,5)"} - {"(7,8)","(10,9)"} - {"(9,10)","(,)"} - {"(0,2)"} - {"(98,100)"} + {"(1,3)","(,)"} + {"(3,5)","(6,5)"} + {"(7,9)","(10,9)"} + {"(9,11)","(,)"} + {"(0,3)"} + {"(98,101)"} (8 rows) +explain (verbose, costs off) + update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; + QUERY PLAN +------------------------------------------------------------------------------------------------------------ + Update on public.dcomptable + -> Seq Scan on public.dcomptable + Output: (d1[1].r := (d1[1].r - 1::double precision))[1].i := (d1[1].i + 1::double precision), ctid + Filter: (dcomptable.d1[1].i > 0::double precision) +(4 rows) + +create rule silly as on delete to dcomptable do instead + update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; +\d+ dcomptable + Table "public.dcomptable" + Column | Type | Modifiers | Storage | Stats target | Description +--------+------------+-----------+----------+--------------+------------- + d1 | dcomptypea | | extended | | +Indexes: + "dcomptable_d1_key" UNIQUE CONSTRAINT, btree (d1) +Rules: + silly AS + ON DELETE TO dcomptable DO INSTEAD UPDATE dcomptable SET d1[1].r = dcomptable.d1[1].r - 1::double precision, d1[1].i = dcomptable.d1[1].i + 1::double precision + WHERE dcomptable.d1[1].i > 0::double precision +Has OIDs: no + drop table dcomptable; drop type comptype cascade; NOTICE: drop cascades to type dcomptypea diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql index fae95c6861b..c149efc347c 100644 --- a/src/test/regress/sql/domain.sql +++ b/src/test/regress/sql/domain.sql @@ -150,9 +150,18 @@ insert into dcomptable (d1[1].r) values(99); insert into dcomptable (d1[1].r, d1[1].i) values(99, 100); insert into dcomptable (d1[1].r, d1[1].i) values(100, 99); -- fail update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0; -- fail -update dcomptable set d1[1].r = d1[1].r - 1 where d1[1].i > 0; +update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; select * from dcomptable; +explain (verbose, costs off) + update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; +create rule silly as on delete to dcomptable do instead + update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1 + where d1[1].i > 0; +\d+ dcomptable + drop table dcomptable; drop type comptype cascade; |