我通过从表中选择数据并插入到另一个表中来更新数据。但也有在其他表中的一些约束,我得到这个:将数据从一个表复制到另一个表
DETAIL: Key (entry_id)=(391) is duplicated.
我基本上做到这一点:
insert into table_tmp
select * from table_one
我怎么能跳过插入时,该键输入重复的发生?
更新我无法保存在SQL小提琴此架构的信息,但在这里它是:
CREATE TABLE table1
("entry_id" int, "text" varchar(255))
;
INSERT INTO table1
("entry_id", "text")
VALUES
(1, 'one'),
(2, 'two'),
(3, 'test'),
(3, 'test'),
(12, 'three'),
(13, 'four')
;
CREATE TABLE table2
("entry_id" int, "text" varchar(255))
;
Create unique index entry_id_idxs
on table2 (entry_id)
where text='test';
INSERT INTO table2
("entry_id", "text")
VALUES
(1, 'one'),
(2, 'two'),
(3, 'test'),
(3, 'test'),
(12, 'three'),
(13, 'four')
;
错误,我得到的,如果我尝试建立架构
你是否用WHERE约束创建唯一索引?为什么?这没有任何意义。请从索引创建中删除WHERE。 – mvp