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
$$
declarerec 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.*);returnnew_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