插入现有表时自动更新主键吗?

问题描述 投票:0回答:1

实际上,我的问题基本上是same as here,但是我需要将嵌套查询中的值插入到现有表中,而我对sql不那么了解,因为它不知道如何将setval部分并入我的查询中:] >

insert into table_a
select * 
from table_b 
where val_1 IN (select "val_1" from table_c where "val_2" is null)

返回

ERROR:  duplicate key value violates unique constraint "table_a_pkey"
DETAIL: Key (qid)=(470971) already exists.

现在,我知道我可以按照here的说明使用drop column和autgenerate进行变通,但是必须有一种更优雅的方法。我正在使用Postgresql / Postgis 2.4 btw。

实际上,我的问题与此处基本相同,但我需要将嵌套查询中的值插入现有表中,而我对sql不太了解,以了解如何合并setval ...

postgresql primary-key sql-insert
1个回答
0
投票
不要插入PK列:
© www.soinside.com 2019 - 2024. All rights reserved.