mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-11-27 07:21:09 +08:00
Fix ON CONFLICT DO NOTHING/UPDATE for temporal indexes
A PRIMARY KEY or UNIQUE constraint with WITHOUT OVERLAPS will be a GiST index, not a B-Tree, but it will still have indisunique set. The code for ON CONFLICT fails if it sees a non-btree index that has indisunique. This commit fixes that and adds some tests. But now that we can't just test indisunique, we also need some extra checks to prevent DO UPDATE from running against a WITHOUT OVERLAPS constraint (because the conflict could happen against more than one row, and we'd only update one). Author: Paul A. Jungwirth <pj@illuminatedcomputing.com> Discussion: https://www.postgresql.org/message-id/1426589a-83cb-4a89-bf40-713970c07e63@illuminatedcomputing.com
This commit is contained in:
parent
5caa057496
commit
144c2ce0cc
@ -210,7 +210,7 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
|
||||
* If the indexes are to be used for speculative insertion, add extra
|
||||
* information required by unique index entries.
|
||||
*/
|
||||
if (speculative && ii->ii_Unique)
|
||||
if (speculative && ii->ii_Unique && !indexDesc->rd_index->indisexclusion)
|
||||
BuildSpeculativeIndexInfo(indexDesc, ii);
|
||||
|
||||
relationDescs[i] = indexDesc;
|
||||
|
@ -815,7 +815,7 @@ infer_arbiter_indexes(PlannerInfo *root)
|
||||
*/
|
||||
if (indexOidFromConstraint == idxForm->indexrelid)
|
||||
{
|
||||
if (!idxForm->indisunique && onconflict->action == ONCONFLICT_UPDATE)
|
||||
if (idxForm->indisexclusion && onconflict->action == ONCONFLICT_UPDATE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("ON CONFLICT DO UPDATE not supported with exclusion constraints")));
|
||||
@ -840,6 +840,13 @@ infer_arbiter_indexes(PlannerInfo *root)
|
||||
if (!idxForm->indisunique)
|
||||
goto next;
|
||||
|
||||
/*
|
||||
* So-called unique constraints with WITHOUT OVERLAPS are really
|
||||
* exclusion constraints, so skip those too.
|
||||
*/
|
||||
if (idxForm->indisexclusion)
|
||||
goto next;
|
||||
|
||||
/* Build BMS representation of plain (non expression) index attrs */
|
||||
indexedAttrs = NULL;
|
||||
for (natt = 0; natt < idxForm->indnkeyatts; natt++)
|
||||
|
@ -453,6 +453,182 @@ DROP TABLE temporal_partitioned;
|
||||
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
||||
ERROR: cannot use non-unique index "temporal_rng_pk" as replica identity
|
||||
--
|
||||
-- ON CONFLICT
|
||||
--
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
[1,2) | [2010-01-01,2020-01-01)
|
||||
[2,3) | [2005-01-01,2006-01-01)
|
||||
(3 rows)
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
[1,2) | [2010-01-01,2020-01-01)
|
||||
[2,3) | [2005-01-01,2006-01-01)
|
||||
(3 rows)
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
-- with a UNIQUE constraint:
|
||||
CREATE TABLE temporal3 (
|
||||
id int4range,
|
||||
valid_at daterange,
|
||||
CONSTRAINT temporal3_uq UNIQUE (id, valid_at WITHOUT OVERLAPS)
|
||||
);
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
[1,2) | [2010-01-01,2020-01-01)
|
||||
[2,3) | [2005-01-01,2006-01-01)
|
||||
(3 rows)
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
[1,2) | [2010-01-01,2020-01-01)
|
||||
[2,3) | [2005-01-01,2006-01-01)
|
||||
(3 rows)
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
id | valid_at
|
||||
-------+-------------------------
|
||||
[1,2) | [2000-01-01,2010-01-01)
|
||||
(1 row)
|
||||
|
||||
DROP TABLE temporal3;
|
||||
--
|
||||
-- test FK dependencies
|
||||
--
|
||||
-- can't drop a range referenced by an FK, unless with CASCADE
|
||||
|
@ -319,6 +319,119 @@ DROP TABLE temporal_partitioned;
|
||||
-- (should fail)
|
||||
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
|
||||
|
||||
--
|
||||
-- ON CONFLICT
|
||||
--
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO NOTHING;
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal_rng;
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal_rng (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal_rng_pk DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
SELECT * FROM temporal_rng ORDER BY id, valid_at;
|
||||
|
||||
-- with a UNIQUE constraint:
|
||||
|
||||
CREATE TABLE temporal3 (
|
||||
id int4range,
|
||||
valid_at daterange,
|
||||
CONSTRAINT temporal3_uq UNIQUE (id, valid_at WITHOUT OVERLAPS)
|
||||
);
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO NOTHING;
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO NOTHING;
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT (id, valid_at) DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
|
||||
TRUNCATE temporal3;
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'));
|
||||
-- with a conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[2,3)';
|
||||
-- id matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[1,2)', daterange('2010-01-01', '2020-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[3,4)';
|
||||
-- date matches but no conflict
|
||||
INSERT INTO temporal3 (id, valid_at) VALUES ('[2,3)', daterange('2005-01-01', '2006-01-01')) ON CONFLICT ON CONSTRAINT temporal3_uq DO UPDATE SET id = EXCLUDED.id + '[4,5)';
|
||||
SELECT * FROM temporal3 ORDER BY id, valid_at;
|
||||
|
||||
DROP TABLE temporal3;
|
||||
|
||||
--
|
||||
-- test FK dependencies
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user