Re: copy record?

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: copy record?
Date: 2011-05-26 21:18:41
Message-ID: 4DDEC3B1.2050008@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Gauthier, Dave wrote:
> 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);

This alleviates the need to trick the back-end using 'where 1-0'
and also does the insert, all in one go.

select * into temp table foo from maintable where primcol=123;
update foo set primcol = 456;
insert into maintable select * from foo;

You also may need this is if you intend to use the same sequence of
calls on within the same session:

drop table foo;

HTH

Bosco.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tarlika Elisabeth Schmitz 2011-05-26 21:45:43 Re: trigger - dynamic WHERE clause
Previous Message Merlin Moncure 2011-05-26 21:17:51 Re: Miidpoint between two long/lat points? (earthdistance?)

Browse pgsql-sql by date

  From Date Subject
Next Message Jasen Betts 2011-05-27 04:45:47 Re: copy record?
Previous Message Gauthier, Dave 2011-05-26 21:04:04 Re: copy record?