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>) |
| Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: