Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1E2759FA4F0 for ; Wed, 7 Feb 2007 20:30:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 61358-04-2 for ; Wed, 7 Feb 2007 20:30:21 -0400 (AST) X-Greylist: delayed 00:23:11.38214 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 02EFD9F9FB2 for ; Wed, 7 Feb 2007 20:30:20 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from bravo.pjkh.com (bravo.pjkh.com [72.36.232.219]) by svr4.postgresql.org (Postfix) with ESMTP id F2E105AF97C for ; Thu, 8 Feb 2007 00:07:05 +0000 (GMT) Received: from bravo.pjkh.com (bravo.pjkh.com [72.36.232.219]) by bravo.pjkh.com (Postfix) with ESMTP id 4CAD013C872; Wed, 7 Feb 2007 18:17:20 -0600 (CST) Received: by bravo.pjkh.com (Postfix, from userid 1000) id F37F013C83C; Wed, 7 Feb 2007 18:17:18 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by bravo.pjkh.com (Postfix) with ESMTP id F246113C82C; Wed, 7 Feb 2007 18:17:18 -0600 (CST) Date: Wed, 7 Feb 2007 18:17:18 -0600 (CST) From: Philip Hallstrom To: Bryce Nesbitt Cc: pgsql-sql@postgresql.org Subject: Re: Seeking quick way to clone a row, but give it a new pk. In-Reply-To: <45CA50E6.6090006@obviously.com> Message-ID: <20070207181622.I3035@bravo.pjkh.com> References: <45CA50E6.6090006@obviously.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: ClamAV using ClamSMTP X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200702/71 X-Sequence-Number: 27405 > 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...