Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b83e8a2

Browse files
committed
Remove support for temporal RESTRICT foreign keys
It isn't clear how these should behave, so let's wait to implement them until we are sure how to do it. This feature was initially added by commit 89f908a, so it hasn't been released yet. Author: Paul A. Jungwirth <pj@illuminatedcomputing.com> Discussion: https://postgr.es/m/e773bc11-4ac1-40de-bb91-814e02f05b6d%40eisentraut.org
1 parent e033696 commit b83e8a2

File tree

4 files changed

+11
-402
lines changed

4 files changed

+11
-402
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
12821282
<quote>no-op</quote> updates that update a column to the same
12831283
value.)
12841284
</para>
1285+
1286+
<para>
1287+
In a temporal foreign key, this option is not supported.
1288+
</para>
12851289
</listitem>
12861290
</varlistentry>
12871291

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10052,15 +10052,17 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
1005210052
*/
1005310053
if (fkconstraint->fk_with_period)
1005410054
{
10055-
if (fkconstraint->fk_upd_action == FKCONSTR_ACTION_CASCADE ||
10055+
if (fkconstraint->fk_upd_action == FKCONSTR_ACTION_RESTRICT ||
10056+
fkconstraint->fk_upd_action == FKCONSTR_ACTION_CASCADE ||
1005610057
fkconstraint->fk_upd_action == FKCONSTR_ACTION_SETNULL ||
1005710058
fkconstraint->fk_upd_action == FKCONSTR_ACTION_SETDEFAULT)
1005810059
ereport(ERROR,
1005910060
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1006010061
errmsg("unsupported %s action for foreign key constraint using PERIOD",
1006110062
"ON UPDATE"));
1006210063

10063-
if (fkconstraint->fk_del_action == FKCONSTR_ACTION_CASCADE ||
10064+
if (fkconstraint->fk_del_action == FKCONSTR_ACTION_RESTRICT ||
10065+
fkconstraint->fk_del_action == FKCONSTR_ACTION_CASCADE ||
1006410066
fkconstraint->fk_del_action == FKCONSTR_ACTION_SETNULL ||
1006510067
fkconstraint->fk_del_action == FKCONSTR_ACTION_SETDEFAULT)
1006610068
ereport(ERROR,

src/test/regress/expected/without_overlaps.out

Lines changed: 3 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,55 +1770,11 @@ ALTER TABLE temporal_fk_rng2rng
17701770
FOREIGN KEY (parent_id, PERIOD valid_at)
17711771
REFERENCES temporal_rng
17721772
ON UPDATE RESTRICT;
1773-
-- a PK update that succeeds because the numeric id isn't referenced:
1774-
INSERT INTO temporal_rng (id, valid_at) VALUES ('[5,6)', daterange('2018-01-01', '2018-02-01'));
1775-
UPDATE temporal_rng SET valid_at = daterange('2016-01-01', '2016-02-01') WHERE id = '[5,6)';
1776-
-- a PK update that succeeds even though the numeric id is referenced because the range isn't:
1777-
DELETE FROM temporal_rng WHERE id = '[5,6)';
1778-
INSERT INTO temporal_rng (id, valid_at) VALUES
1779-
('[5,6)', daterange('2018-01-01', '2018-02-01')),
1780-
('[5,6)', daterange('2018-02-01', '2018-03-01'));
1781-
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES
1782-
('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)');
1783-
UPDATE temporal_rng SET valid_at = daterange('2016-02-01', '2016-03-01')
1784-
WHERE id = '[5,6)' AND valid_at = daterange('2018-02-01', '2018-03-01');
1785-
-- A PK update sliding the edge between two referenced rows:
1786-
INSERT INTO temporal_rng (id, valid_at) VALUES
1787-
('[6,7)', daterange('2018-01-01', '2018-02-01')),
1788-
('[6,7)', daterange('2018-02-01', '2018-03-01'));
1789-
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES
1790-
('[4,5)', daterange('2018-01-15', '2018-02-15'), '[6,7)');
1791-
UPDATE temporal_rng
1792-
SET valid_at = CASE WHEN lower(valid_at) = '2018-01-01' THEN daterange('2018-01-01', '2018-01-05')
1793-
WHEN lower(valid_at) = '2018-02-01' THEN daterange('2018-01-05', '2018-03-01') END
1794-
WHERE id = '[6,7)';
1795-
ERROR: update or delete on table "temporal_rng" violates RESTRICT setting of foreign key constraint "temporal_fk_rng2rng_fk" on table "temporal_fk_rng2rng"
1796-
DETAIL: Key (id, valid_at)=([6,7), [2018-01-01,2018-02-01)) is referenced from table "temporal_fk_rng2rng".
1797-
-- a PK update that fails because both are referenced (even before commit):
1798-
BEGIN;
1799-
ALTER TABLE temporal_fk_rng2rng
1800-
ALTER CONSTRAINT temporal_fk_rng2rng_fk
1801-
DEFERRABLE INITIALLY DEFERRED;
1802-
UPDATE temporal_rng SET valid_at = daterange('2016-01-01', '2016-02-01')
1803-
WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
1804-
ERROR: update or delete on table "temporal_rng" violates RESTRICT setting of foreign key constraint "temporal_fk_rng2rng_fk" on table "temporal_fk_rng2rng"
1805-
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is referenced from table "temporal_fk_rng2rng".
1806-
ROLLBACK;
1807-
-- changing the scalar part fails:
1808-
UPDATE temporal_rng SET id = '[7,8)'
1809-
WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
1810-
ERROR: update or delete on table "temporal_rng" violates RESTRICT setting of foreign key constraint "temporal_fk_rng2rng_fk" on table "temporal_fk_rng2rng"
1811-
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is referenced from table "temporal_fk_rng2rng".
1812-
-- then delete the objecting FK record and the same PK update succeeds:
1813-
DELETE FROM temporal_fk_rng2rng WHERE id = '[3,4)';
1814-
UPDATE temporal_rng SET valid_at = daterange('2016-01-01', '2016-02-01')
1815-
WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
1773+
ERROR: unsupported ON UPDATE action for foreign key constraint using PERIOD
18161774
--
18171775
-- test FK referenced deletes NO ACTION
18181776
--
18191777
TRUNCATE temporal_rng, temporal_fk_rng2rng;
1820-
ALTER TABLE temporal_fk_rng2rng
1821-
DROP CONSTRAINT temporal_fk_rng2rng_fk;
18221778
ALTER TABLE temporal_fk_rng2rng
18231779
ADD CONSTRAINT temporal_fk_rng2rng_fk
18241780
FOREIGN KEY (parent_id, PERIOD valid_at)
@@ -1860,35 +1816,14 @@ ALTER TABLE temporal_fk_rng2rng
18601816
FOREIGN KEY (parent_id, PERIOD valid_at)
18611817
REFERENCES temporal_rng
18621818
ON DELETE RESTRICT;
1863-
INSERT INTO temporal_rng (id, valid_at) VALUES ('[5,6)', daterange('2018-01-01', '2018-02-01'));
1864-
DELETE FROM temporal_rng WHERE id = '[5,6)';
1865-
-- a PK delete that succeeds even though the numeric id is referenced because the range isn't:
1866-
INSERT INTO temporal_rng (id, valid_at) VALUES
1867-
('[5,6)', daterange('2018-01-01', '2018-02-01')),
1868-
('[5,6)', daterange('2018-02-01', '2018-03-01'));
1869-
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES
1870-
('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)');
1871-
DELETE FROM temporal_rng WHERE id = '[5,6)' AND valid_at = daterange('2018-02-01', '2018-03-01');
1872-
-- a PK delete that fails because both are referenced (even before commit):
1873-
BEGIN;
1874-
ALTER TABLE temporal_fk_rng2rng
1875-
ALTER CONSTRAINT temporal_fk_rng2rng_fk
1876-
DEFERRABLE INITIALLY DEFERRED;
1877-
DELETE FROM temporal_rng WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
1878-
ERROR: update or delete on table "temporal_rng" violates RESTRICT setting of foreign key constraint "temporal_fk_rng2rng_fk" on table "temporal_fk_rng2rng"
1879-
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is referenced from table "temporal_fk_rng2rng".
1880-
ROLLBACK;
1881-
-- then delete the objecting FK record and the same PK delete succeeds:
1882-
DELETE FROM temporal_fk_rng2rng WHERE id = '[3,4)';
1883-
DELETE FROM temporal_rng WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
1819+
ERROR: unsupported ON DELETE action for foreign key constraint using PERIOD
18841820
--
18851821
-- test ON UPDATE/DELETE options
18861822
--
18871823
-- test FK referenced updates CASCADE
18881824
INSERT INTO temporal_rng (id, valid_at) VALUES ('[6,7)', daterange('2018-01-01', '2021-01-01'));
18891825
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES ('[4,5)', daterange('2018-01-01', '2021-01-01'), '[6,7)');
18901826
ALTER TABLE temporal_fk_rng2rng
1891-
DROP CONSTRAINT temporal_fk_rng2rng_fk,
18921827
ADD CONSTRAINT temporal_fk_rng2rng_fk
18931828
FOREIGN KEY (parent_id, PERIOD valid_at)
18941829
REFERENCES temporal_rng
@@ -1898,7 +1833,6 @@ ERROR: unsupported ON UPDATE action for foreign key constraint using PERIOD
18981833
INSERT INTO temporal_rng (id, valid_at) VALUES ('[9,10)', daterange('2018-01-01', '2021-01-01'));
18991834
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES ('[6,7)', daterange('2018-01-01', '2021-01-01'), '[9,10)');
19001835
ALTER TABLE temporal_fk_rng2rng
1901-
DROP CONSTRAINT temporal_fk_rng2rng_fk,
19021836
ADD CONSTRAINT temporal_fk_rng2rng_fk
19031837
FOREIGN KEY (parent_id, PERIOD valid_at)
19041838
REFERENCES temporal_rng
@@ -1910,7 +1844,6 @@ INSERT INTO temporal_rng (id, valid_at) VALUES ('[12,13)', daterange('2018-01-01
19101844
INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES ('[8,9)', daterange('2018-01-01', '2021-01-01'), '[12,13)');
19111845
ALTER TABLE temporal_fk_rng2rng
19121846
ALTER COLUMN parent_id SET DEFAULT '[-1,-1]',
1913-
DROP CONSTRAINT temporal_fk_rng2rng_fk,
19141847
ADD CONSTRAINT temporal_fk_rng2rng_fk
19151848
FOREIGN KEY (parent_id, PERIOD valid_at)
19161849
REFERENCES temporal_rng
@@ -2289,51 +2222,11 @@ ALTER TABLE temporal_fk_mltrng2mltrng
22892222
FOREIGN KEY (parent_id, PERIOD valid_at)
22902223
REFERENCES temporal_mltrng (id, PERIOD valid_at)
22912224
ON UPDATE RESTRICT;
2292-
-- a PK update that succeeds because the numeric id isn't referenced:
2293-
INSERT INTO temporal_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01')));
2294-
UPDATE temporal_mltrng SET valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) WHERE id = '[5,6)';
2295-
-- a PK update that succeeds even though the numeric id is referenced because the range isn't:
2296-
DELETE FROM temporal_mltrng WHERE id = '[5,6)';
2297-
INSERT INTO temporal_mltrng (id, valid_at) VALUES
2298-
('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))),
2299-
('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01')));
2300-
INSERT INTO temporal_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES
2301-
('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)');
2302-
UPDATE temporal_mltrng SET valid_at = datemultirange(daterange('2016-02-01', '2016-03-01'))
2303-
WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-02-01', '2018-03-01'));
2304-
-- A PK update sliding the edge between two referenced rows:
2305-
INSERT INTO temporal_mltrng (id, valid_at) VALUES
2306-
('[6,7)', datemultirange(daterange('2018-01-01', '2018-02-01'))),
2307-
('[6,7)', datemultirange(daterange('2018-02-01', '2018-03-01')));
2308-
INSERT INTO temporal_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES
2309-
('[4,5)', datemultirange(daterange('2018-01-15', '2018-02-15')), '[6,7)');
2310-
UPDATE temporal_mltrng
2311-
SET valid_at = CASE WHEN lower(valid_at) = '2018-01-01' THEN datemultirange(daterange('2018-01-01', '2018-01-05'))
2312-
WHEN lower(valid_at) = '2018-02-01' THEN datemultirange(daterange('2018-01-05', '2018-03-01')) END
2313-
WHERE id = '[6,7)';
2314-
ERROR: update or delete on table "temporal_mltrng" violates RESTRICT setting of foreign key constraint "temporal_fk_mltrng2mltrng_fk" on table "temporal_fk_mltrng2mltrng"
2315-
DETAIL: Key (id, valid_at)=([6,7), {[2018-01-01,2018-02-01)}) is referenced from table "temporal_fk_mltrng2mltrng".
2316-
-- a PK update that fails because both are referenced (even before commit):
2317-
BEGIN;
2318-
ALTER TABLE temporal_fk_mltrng2mltrng
2319-
ALTER CONSTRAINT temporal_fk_mltrng2mltrng_fk
2320-
DEFERRABLE INITIALLY DEFERRED;
2321-
UPDATE temporal_mltrng SET valid_at = datemultirange(daterange('2016-01-01', '2016-02-01'))
2322-
WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-01-01', '2018-02-01'));
2323-
ERROR: update or delete on table "temporal_mltrng" violates RESTRICT setting of foreign key constraint "temporal_fk_mltrng2mltrng_fk" on table "temporal_fk_mltrng2mltrng"
2324-
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is referenced from table "temporal_fk_mltrng2mltrng".
2325-
ROLLBACK;
2326-
-- changing the scalar part fails:
2327-
UPDATE temporal_mltrng SET id = '[7,8)'
2328-
WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-01-01', '2018-02-01'));
2329-
ERROR: update or delete on table "temporal_mltrng" violates RESTRICT setting of foreign key constraint "temporal_fk_mltrng2mltrng_fk" on table "temporal_fk_mltrng2mltrng"
2330-
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is referenced from table "temporal_fk_mltrng2mltrng".
2225+
ERROR: unsupported ON UPDATE action for foreign key constraint using PERIOD
23312226
--
23322227
-- test FK referenced deletes NO ACTION
23332228
--
23342229
TRUNCATE temporal_mltrng, temporal_fk_mltrng2mltrng;
2335-
ALTER TABLE temporal_fk_mltrng2mltrng
2336-
DROP CONSTRAINT temporal_fk_mltrng2mltrng_fk;
23372230
ALTER TABLE temporal_fk_mltrng2mltrng
23382231
ADD CONSTRAINT temporal_fk_mltrng2mltrng_fk
23392232
FOREIGN KEY (parent_id, PERIOD valid_at)
@@ -2361,34 +2254,6 @@ COMMIT;
23612254
ERROR: update or delete on table "temporal_mltrng" violates foreign key constraint "temporal_fk_mltrng2mltrng_fk" on table "temporal_fk_mltrng2mltrng"
23622255
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is still referenced from table "temporal_fk_mltrng2mltrng".
23632256
--
2364-
-- test FK referenced deletes RESTRICT
2365-
--
2366-
TRUNCATE temporal_mltrng, temporal_fk_mltrng2mltrng;
2367-
ALTER TABLE temporal_fk_mltrng2mltrng
2368-
DROP CONSTRAINT temporal_fk_mltrng2mltrng_fk;
2369-
ALTER TABLE temporal_fk_mltrng2mltrng
2370-
ADD CONSTRAINT temporal_fk_mltrng2mltrng_fk
2371-
FOREIGN KEY (parent_id, PERIOD valid_at)
2372-
REFERENCES temporal_mltrng (id, PERIOD valid_at)
2373-
ON DELETE RESTRICT;
2374-
INSERT INTO temporal_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01')));
2375-
DELETE FROM temporal_mltrng WHERE id = '[5,6)';
2376-
-- a PK delete that succeeds even though the numeric id is referenced because the range isn't:
2377-
INSERT INTO temporal_mltrng (id, valid_at) VALUES
2378-
('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))),
2379-
('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01')));
2380-
INSERT INTO temporal_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)');
2381-
DELETE FROM temporal_mltrng WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-02-01', '2018-03-01'));
2382-
-- a PK delete that fails because both are referenced (even before commit):
2383-
BEGIN;
2384-
ALTER TABLE temporal_fk_mltrng2mltrng
2385-
ALTER CONSTRAINT temporal_fk_mltrng2mltrng_fk
2386-
DEFERRABLE INITIALLY DEFERRED;
2387-
DELETE FROM temporal_mltrng WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-01-01', '2018-02-01'));
2388-
ERROR: update or delete on table "temporal_mltrng" violates RESTRICT setting of foreign key constraint "temporal_fk_mltrng2mltrng_fk" on table "temporal_fk_mltrng2mltrng"
2389-
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is referenced from table "temporal_fk_mltrng2mltrng".
2390-
ROLLBACK;
2391-
--
23922257
-- FK between partitioned tables: ranges
23932258
--
23942259
CREATE TABLE temporal_partitioned_rng (
@@ -2469,40 +2334,6 @@ DELETE FROM temporal_partitioned_rng WHERE id = '[5,6)' AND valid_at = daterange
24692334
ERROR: update or delete on table "tp1" violates foreign key constraint "temporal_partitioned_fk_rng2rng_parent_id_valid_at_fkey" on table "temporal_partitioned_fk_rng2rng"
24702335
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is still referenced from table "temporal_partitioned_fk_rng2rng".
24712336
--
2472-
-- partitioned FK referenced updates RESTRICT
2473-
--
2474-
TRUNCATE temporal_partitioned_rng, temporal_partitioned_fk_rng2rng;
2475-
ALTER TABLE temporal_partitioned_fk_rng2rng
2476-
DROP CONSTRAINT temporal_partitioned_fk_rng2rng_fk;
2477-
ALTER TABLE temporal_partitioned_fk_rng2rng
2478-
ADD CONSTRAINT temporal_partitioned_fk_rng2rng_fk
2479-
FOREIGN KEY (parent_id, PERIOD valid_at)
2480-
REFERENCES temporal_partitioned_rng
2481-
ON DELETE RESTRICT;
2482-
INSERT INTO temporal_partitioned_rng (id, valid_at) VALUES ('[5,6)', daterange('2016-01-01', '2016-02-01'));
2483-
UPDATE temporal_partitioned_rng SET valid_at = daterange('2018-01-01', '2018-02-01') WHERE id = '[5,6)';
2484-
INSERT INTO temporal_partitioned_rng (id, valid_at) VALUES ('[5,6)', daterange('2018-02-01', '2018-03-01'));
2485-
INSERT INTO temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) VALUES ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)');
2486-
UPDATE temporal_partitioned_rng SET valid_at = daterange('2016-02-01', '2016-03-01')
2487-
WHERE id = '[5,6)' AND valid_at = daterange('2018-02-01', '2018-03-01');
2488-
-- should fail:
2489-
UPDATE temporal_partitioned_rng SET valid_at = daterange('2016-01-01', '2016-02-01')
2490-
WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
2491-
ERROR: update or delete on table "tp1" violates foreign key constraint "temporal_partitioned_fk_rng2rng_parent_id_valid_at_fkey" on table "temporal_partitioned_fk_rng2rng"
2492-
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is still referenced from table "temporal_partitioned_fk_rng2rng".
2493-
--
2494-
-- partitioned FK referenced deletes RESTRICT
2495-
--
2496-
TRUNCATE temporal_partitioned_rng, temporal_partitioned_fk_rng2rng;
2497-
INSERT INTO temporal_partitioned_rng (id, valid_at) VALUES ('[5,6)', daterange('2018-01-01', '2018-02-01'));
2498-
INSERT INTO temporal_partitioned_rng (id, valid_at) VALUES ('[5,6)', daterange('2018-02-01', '2018-03-01'));
2499-
INSERT INTO temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) VALUES ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)');
2500-
DELETE FROM temporal_partitioned_rng WHERE id = '[5,6)' AND valid_at = daterange('2018-02-01', '2018-03-01');
2501-
-- should fail:
2502-
DELETE FROM temporal_partitioned_rng WHERE id = '[5,6)' AND valid_at = daterange('2018-01-01', '2018-02-01');
2503-
ERROR: update or delete on table "tp1" violates RESTRICT setting of foreign key constraint "temporal_partitioned_fk_rng2rng_parent_id_valid_at_fkey" on table "temporal_partitioned_fk_rng2rng"
2504-
DETAIL: Key (id, valid_at)=([5,6), [2018-01-01,2018-02-01)) is referenced from table "temporal_partitioned_fk_rng2rng".
2505-
--
25062337
-- partitioned FK referenced updates CASCADE
25072338
--
25082339
ALTER TABLE temporal_partitioned_fk_rng2rng
@@ -2625,40 +2456,6 @@ DELETE FROM temporal_partitioned_mltrng WHERE id = '[5,6)' AND valid_at = datemu
26252456
ERROR: update or delete on table "tp1" violates foreign key constraint "temporal_partitioned_fk_mltrng2mltrng_parent_id_valid_at_fkey1" on table "temporal_partitioned_fk_mltrng2mltrng"
26262457
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is still referenced from table "temporal_partitioned_fk_mltrng2mltrng".
26272458
--
2628-
-- partitioned FK referenced updates RESTRICT
2629-
--
2630-
TRUNCATE temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng;
2631-
ALTER TABLE temporal_partitioned_fk_mltrng2mltrng
2632-
DROP CONSTRAINT temporal_partitioned_fk_mltrng2mltrng_fk;
2633-
ALTER TABLE temporal_partitioned_fk_mltrng2mltrng
2634-
ADD CONSTRAINT temporal_partitioned_fk_mltrng2mltrng_fk
2635-
FOREIGN KEY (parent_id, PERIOD valid_at)
2636-
REFERENCES temporal_partitioned_mltrng
2637-
ON DELETE RESTRICT;
2638-
INSERT INTO temporal_partitioned_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2016-01-01', '2016-02-01')));
2639-
UPDATE temporal_partitioned_mltrng SET valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')) WHERE id = '[5,6)';
2640-
INSERT INTO temporal_partitioned_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01')));
2641-
INSERT INTO temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)');
2642-
UPDATE temporal_partitioned_mltrng SET valid_at = datemultirange(daterange('2016-02-01', '2016-03-01'))
2643-
WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-02-01', '2018-03-01'));
2644-
-- should fail:
2645-
UPDATE temporal_partitioned_mltrng SET valid_at = datemultirange(daterange('2016-01-01', '2016-02-01'))
2646-
WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-01-01', '2018-02-01'));
2647-
ERROR: update or delete on table "tp1" violates foreign key constraint "temporal_partitioned_fk_mltrng2mltrng_parent_id_valid_at_fkey1" on table "temporal_partitioned_fk_mltrng2mltrng"
2648-
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is still referenced from table "temporal_partitioned_fk_mltrng2mltrng".
2649-
--
2650-
-- partitioned FK referenced deletes RESTRICT
2651-
--
2652-
TRUNCATE temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng;
2653-
INSERT INTO temporal_partitioned_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01')));
2654-
INSERT INTO temporal_partitioned_mltrng (id, valid_at) VALUES ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01')));
2655-
INSERT INTO temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)');
2656-
DELETE FROM temporal_partitioned_mltrng WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-02-01', '2018-03-01'));
2657-
-- should fail:
2658-
DELETE FROM temporal_partitioned_mltrng WHERE id = '[5,6)' AND valid_at = datemultirange(daterange('2018-01-01', '2018-02-01'));
2659-
ERROR: update or delete on table "tp1" violates RESTRICT setting of foreign key constraint "temporal_partitioned_fk_mltrng2mltrng_parent_id_valid_at_fkey1" on table "temporal_partitioned_fk_mltrng2mltrng"
2660-
DETAIL: Key (id, valid_at)=([5,6), {[2018-01-01,2018-02-01)}) is referenced from table "temporal_partitioned_fk_mltrng2mltrng".
2661-
--
26622459
-- partitioned FK referenced updates CASCADE
26632460
--
26642461
ALTER TABLE temporal_partitioned_fk_mltrng2mltrng

0 commit comments

Comments
 (0)