Re: Seeking quick way to clone a row, but give it a new pk.

From: Philip Hallstrom <postgresql(at)philip(dot)pjkh(dot)com>
To: Bryce Nesbitt <bryce1(at)obviously(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Seeking quick way to clone a row, but give it a new pk.
Date: 2007-02-08 00:17:18
Message-ID: 20070207181622.I3035@bravo.pjkh.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Karthikeyan Sundaram 2007-02-08 00:49:45 question on passing parameter in sql query
Previous Message Greg Wittel 2007-02-07 22:43:13 Odd PL/PgSQL Error -- relation "X" does not exist when using index expression