[英]How to use ON CONFLICT with Exclusion Constraint?
for example: index by userid
, sdate
, edate
例如:index by
userid
, sdate
, edate
userid sdate edate
001 2019-01-01 2019-01-30
if I insert new data like: 如果我插入新数据,如:
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
I tried below using GIST, but how to combine it using ON CONFLICT
? 我在下面尝试使用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
I got: 我有:
ERROR: ON CONFLICT DO UPDATE not supported with exclusion constraints
based on the above scenario, I expect, the following: 根据上述情况,我希望如下:
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() shows: 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
You cannot use INSERT ... ON CONFLICT
with an exclusion index, like the error message says. 您不能使用
INSERT ... ON CONFLICT
与排除索引,如错误消息所示。
You will have to use code like in example 43.2 from the documentation . 您必须使用文档中的示例43.2中的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.