pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Hallstrom <postgresql@philip.pjkh.com>
To: Bryce Nesbitt <bryce1@obviously.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Seeking quick way to clone a row, but give it a new pk.
Date: Wed, 7 Feb 2007 18:17:18 -0600 (CST)
Message-ID: <20070207181622.I3035@bravo.pjkh.com> (raw)
In-Reply-To: <45CA50E6.6090006@obviously.com>
References: <45CA50E6.6090006@obviously.com>

> 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...



view thread (8+ messages)  latest in thread

Message-ID: <20070207181622.I3035@bravo.pjkh.com>
Permalink:  ../20070207181622.I3035@bravo.pjkh.com/
Also on:    postgresql.org/message-id/20070207181622.I3035@bravo.pjkh.com

 · 

reply

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: postgresql@philip.pjkh.com, bryce1@obviously.com
  Subject: Re: Seeking quick way to clone a row, but give it a new pk.
  In-Reply-To: <20070207181622.I3035@bravo.pjkh.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