Re: copy record? - Mailing list pgsql-general

From Bosco Rama
Subject Re: copy record?
Date
Msg-id 4DDEC3B1.2050008@boscorama.com
Whole thread Raw
In response to Re: copy record?  ("Gauthier, Dave" <dave.gauthier@intel.com>)
List pgsql-general
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.

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Miidpoint between two long/lat points? (earthdistance?)
Next
From: Tarlika Elisabeth Schmitz
Date:
Subject: Re: trigger - dynamic WHERE clause