Re: Seeking quick way to clone a row, but give it a new pk.

Поиск
Список
Период
Сортировка
Искать
От
John DeSoi
Тема
Re: Seeking quick way to clone a row, but give it a new pk.
Дата
Msg-id
5F25919B-421C-4C6B-A749-E4366A506D14@pgedit.com
Ответ на
Список
Дерево обсуждения
Seeking quick way to clone a row, but give it a new pk. Bryce Nesbitt <bryce1@obviously.com>
Re: Seeking quick way to clone a row, but give it a new pk. Philip Hallstrom <postgresql@philip.pjkh.com>
Re: Seeking quick way to clone a row, but give it a new pk. Bryce Nesbitt <bryce1@obviously.com>
Re: Seeking quick way to clone a row, but give it a new pk. Achilleas Mantzios <achill@matrix.gatewaynet.com>
Re: Seeking quick way to clone a row, but give it a new pk. Aarni Ruuhimäki <aarni@kymi.com>
Re: Seeking quick way to clone a row, but give it a new pk. "Greg Sabino Mullane" <greg@turnstep.com>
Re: Seeking quick way to clone a row, but give it a new pk. John DeSoi <desoi@pgedit.com>
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.*);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


В списке pgsql-sql по дате отправления
От: George Pavlov
Дата:
От: Tom Lane
Дата:
FAQ