例如:索引userid
, sdate
,edate
userid sdate edate
001 2019-01-01 2019-01-30
如果我插入新数据,例如:
userid sdate edate
001 2019-01-03 2019-01-20
or
001 2019-01-13 2019-02-10
or
001 2019-02-01 2019-02-15
我在下面尝试使用 GIST,但是如何使用它来组合它ON CONFLICT
?
CREATE EXTENSION btree_gist
CREATE TABLE test(
ID INT PRIMARY KEY NOT NULL,
USERID CHAR(5),
SDATE DATE,
EDATE DATE,
EXCLUDE USING gist
(USERID WITH =,
daterange(SDATE, EDATE, '[]') WITH &&)
);
Insert Into test (usersid, sdate, edate)
Values (@UsersId, @SDate, @EDate)
ON Conflict ON CONSTRAINT test_userid_daterange_excl
Do Update
Set sdate = @SDate, edate = @EDate
我有:
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
基于上述情况,我预计以下情况:
userid sdate edate I_EXPECT
001 2019-01-03 2019-01-20 UPDATE because it is in range
001 2019-01-13 2019-02-10 UPDATE because it is in range
001 2019-02-01 2019-02-15 INSERT because it is not in range
选择版本()显示:
PostgreSQL 10.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit