A pl/pgsql function can do this easily. Something like this (not
tested):
create or replace function dup_my_table(old_key text, new_key text)
returns text as
$$
declare
rec my_table;
begin;
select into rec * from my_table where key_field = old_key;
rec.key_field = new_key;
insert into my_table values (rec.*);
return new_key;
end;
$$ language plpgsql;
On Feb 7, 2007, at 4:21 PM, Bryce Nesbitt wrote:
I need to create some nearly identical copies of rows in a complicated
table.
Is there a handy syntax that would let me copy a existing row, but
get a
new primary key for the copy? I'd then go in an edit the 1 or 2
additional columns that differ. The duplicate would be in the same
table as the original.
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq