将PostgreSQL数据复制到同一个表中,替换一些字段

时间:2014-06-24 12:38:24

标签: sql postgresql

我有一个包含三列的表格:

id, 
name:string, 
location:int

我需要将location = 14的所有记录复制到同一个表中,但我需要将副本更改为15。当然,id也必须改为自动增量值。

我如何在PostgreSQL中做到这一点?

1 个答案:

答案 0 :(得分:2)

insert into t (name, location)
select name, 15
from t
where location = 14