例如:
按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
select version()显示:
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
答案 0 :(得分:0)
您不能将INSERT ... ON CONFLICT
与排除索引一起使用,如错误消息所示。
您将不得不使用the documentation中的示例43.2中的代码。