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

Поиск
Список
Период
Сортировка
От Aarni Ruuhimäki
Тема Re: Seeking quick way to clone a row, but give it a new pk.
Дата
Msg-id 200702081132.58609.aarni@kymi.com
обсуждение исходный текст
Ответ на Re: Seeking quick way to clone a row, but give it a new pk.  (Bryce Nesbitt <bryce1@obviously.com>)
Список pgsql-sql
On Thursday 08 February 2007 09:19, Bryce Nesbitt wrote:
> >
> > INSERT INTO mytable SELECT * FROM mytable WHERE pk = 123;
> >
> > Or something close to that... I suspect if you changed the '*' to the
> > columns you wanted you could also work in the other columns you want
> > to change as well...
>
> But that will violate the unique primary key constraint:
>
> insert into xx_plan_rule select * from xx_plan_rule where rule_id=9;
> ERROR:  duplicate key violates unique constraint "xx_plan_rule_pkey"

It will, because you are copying all columns, including the pk.

Try:

INSERT INTO mytable (colname_1, colname_2, colname_3)
SELECT (colname_1, colname_2, colname_3)
FROM mytable WHERE pk = 123;

BR,
--
Aarni Ruuhimäki



В списке pgsql-sql по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: metaphone and nysiis in postgres
Следующее
От: Aarni Ruuhimäki
Дата:
Сообщение: Re: interval as hours or minutes ?