From: Bosco Rama <postgres@boscorama.com>
To: Gauthier, Dave <dave.gauthier@intel.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: copy record?
Date: Thu, 26 May 2011 14:18:41 -0700
Message-ID: <4DDEC3B1.2050008@boscorama.com> (raw)
In-Reply-To: <482E80323A35A54498B8B70FF2B87980049413B673@azsmsx504.amr.corp.intel.com>
References: <482E80323A35A54498B8B70FF2B87980049413B5EB@azsmsx504.amr.corp.intel.com>
<482E80323A35A54498B8B70FF2B87980049413B673@azsmsx504.amr.corp.intel.com>
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.
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: postgres@boscorama.com, dave.gauthier@intel.com, pgsql-general@postgresql.org
Subject: Re: copy record?
In-Reply-To: <4DDEC3B1.2050008@boscorama.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