Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id D168E9FA5DD for ; Thu, 8 Feb 2007 03:19:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 39888-03 for ; Thu, 8 Feb 2007 03:19:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from outD.internet-mail-service.net (outD.internet-mail-service.net [216.240.47.227]) by postgresql.org (Postfix) with ESMTP id 09E039FA36A for ; Thu, 8 Feb 2007 03:19:50 -0400 (AST) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Wed, 07 Feb 2007 22:57:17 -0800 Received: from [192.168.1.109] (adsl-71-135-160-185.dsl.pltn13.pacbell.net [71.135.160.185]) by idiom.com (Postfix) with ESMTP id 8058A125B23; Wed, 7 Feb 2007 23:19:47 -0800 (PST) Message-ID: <45CACF12.1060800@obviously.com> Date: Wed, 07 Feb 2007 23:19:46 -0800 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061107 SUSE/1.0.99-18 SeaMonkey/1.1b MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: Philip Hallstrom Subject: Re: Seeking quick way to clone a row, but give it a new pk. References: <45CA50E6.6090006@obviously.com> <20070207181622.I3035@bravo.pjkh.com> In-Reply-To: <20070207181622.I3035@bravo.pjkh.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.031 tagged_above=0 required=5 tests=AWL, BAYES_40 X-Spam-Level: X-Archive-Number: 200702/75 X-Sequence-Number: 27409 Philip Hallstrom 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. >> >> This would save me a bunch of typing. Can it be done? > > 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" -- ---- Visit http://www.obviously.com/