Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 14A079FB1DC for ; Thu, 8 Feb 2007 05:33:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 38844-02 for ; Thu, 8 Feb 2007 05:33:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtp20.kymp.net (smtp20.kymp.net [80.248.96.137]) by postgresql.org (Postfix) with ESMTP id 9AE509FA50C for ; Thu, 8 Feb 2007 05:33:08 -0400 (AST) Received: from kymifedora (static-241-66.kymp.net [213.130.241.66]) by smtp20.kymp.net (8.13.3/8.13.3) with SMTP id l189Wxmp001521; Thu, 8 Feb 2007 11:32:59 +0200 From: Aarni =?iso-8859-1?q?Ruuhim=E4ki?= Reply-To: aarni@kymi.com Organization: KYMI.com To: pgsql-sql@postgresql.org Subject: Re: Seeking quick way to clone a row, but give it a new pk. Date: Thu, 8 Feb 2007 11:32:58 +0200 User-Agent: KMail/1.6.2 References: <45CA50E6.6090006@obviously.com> <20070207181622.I3035@bravo.pjkh.com> <45CACF12.1060800@obviously.com> In-Reply-To: <45CACF12.1060800@obviously.com> Cc: Philip Hallstrom MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200702081132.58609.aarni@kymi.com> X-Virus-Scanned: by amavisd-new X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.035 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200702/78 X-Sequence-Number: 27412 On Thursday 08 February 2007 09:19, Bryce Nesbitt wrote: > > > > INSERT INTO mytable SELECT * FROM mytable WHERE pk =3D 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=3D9; > 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)=20 SELECT (colname_1, colname_2, colname_3)=20 =46ROM mytable WHERE pk =3D 123; BR, =2D-=20 Aarni Ruuhim=E4ki