Re: copy record? - Mailing list pgsql-general

From Gauthier, Dave
Subject Re: copy record?
Date
Msg-id 482E80323A35A54498B8B70FF2B87980049413B673@azsmsx504.amr.corp.intel.com
Whole thread Raw
In response to copy record?  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Responses Re: copy record?  (Bosco Rama <postgres@boscorama.com>)
List pgsql-general

Well, I found a better way, but still open to suggestions.

 

This is what I have so far...

 

create temporary table foo as select * from maintable where 1-0;  -- Credit 4 this goes to a post in the PG archives

insert into foo (select * from maintable where primcol=123);

update foo, set primcol=456;

insert into maintable (select * from foo);

 

 

 

From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Gauthier, Dave
Sent: Thursday, May 26, 2011 4:24 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] copy record?

 

Hi:

 

From within a perl/DBI script, I want to be able to make a copy of a record in a table, changing only the value of the primary key.  I don't know in advance what all the columns are, just the table name.

 

I suppose I could pull the column names for the table from the metadata, query the table/record for the values to copy, build an insert statement from all of that and run it.  But is there a simpler, more elegant way to do this?

 

Thanks for any help !  

pgsql-general by date:

Previous
From: "Brent Wood"
Date:
Subject: Re: Miidpoint between two long/lat points? (earthdistance?)
Next
From: Merlin Moncure
Date:
Subject: Re: Miidpoint between two long/lat points? (earthdistance?)