From: Aarni Ruuhimäki <aarni@kymi.com>
To: pgsql-sql@postgresql.org
Cc: Philip Hallstrom <postgresql@philip.pjkh.com>
Subject: Re: Seeking quick way to clone a row, but give it a new pk.
Date: Thu, 8 Feb 2007 11:32:58 +0200
Message-ID: <200702081132.58609.aarni@kymi.com> (raw)
In-Reply-To: <45CACF12.1060800@obviously.com>
References: <45CA50E6.6090006@obviously.com>
<20070207181622.I3035@bravo.pjkh.com>
<45CACF12.1060800@obviously.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: aarni@kymi.com, postgresql@philip.pjkh.com
Subject: Re: Seeking quick way to clone a row, but give it a new pk.
In-Reply-To: <200702081132.58609.aarni@kymi.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox