I\'m using PostgreSQL 9.3.
I want to duplicate some of the db records. Since I\'m using an auto-increment pk id for the table, I want to get back the id mappings fro
if id column of posts generated by nextval('posts_id_seq'::regclass)
you can manually call this function for every new row
with
sel as (
SELECT id, title, nextval('posts_id_seq'::regclass) new_id
FROM posts
WHERE id IN (1,2)
),
ins as (
INSERT INTO posts (id, title)
SELECT new_id, title
FROM sel
)
SELECT id, new_id
FROM sel
it'l works with any data, include non-unique title