Re: Select into

From: Joe <dev(at)freedomcircle(dot)net>
To: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Cc: Gavin 'Beau' Baumanis <gavinb(at)eclinic(dot)com(dot)au>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Select into
Date: 2008-03-20 13:38:23
Message-ID: 47E268CF.3040604@freedomcircle.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gurjeet Singh wrote:
> Except that it doesn't work... Did you try to execute that query; I am
> assuming not.
Of course I did, do you think I create results by editing them into my
email?

The script:

delete from t1;
insert into t1 values (1, 123, 'first record');
insert into t1 values (2, 456, 'second record');
insert into t1 values (3, 789, 'third record');
select * from t1;
update t1 set col2 = t1copy.col2, col3 = t1copy.col3
from t1 as t1copy
where t1.col1 = 1 and t1copy.col1 = 3;
select * from t1;
select version();

The output:

DELETE 3
INSERT 0 1
INSERT 0 1
INSERT 0 1
col1 | col2 | col3
------+------+---------------
1 | 123 | first record
2 | 456 | second record
3 | 789 | third record
(3 rows)

UPDATE 1
col1 | col2 | col3
------+------+---------------
2 | 456 | second record
3 | 789 | third record
1 | 789 | third record
(3 rows)

version
------------------------------------------------------------------------
PostgreSQL 8.1.9 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.3
(1 row)

And BTW, I also tried your UPDATE SET (salary, name) but that only
works on PG 8.2 and above. I don't see why my query would fail in
subsequent releases.

Joe

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Peters 2008-03-20 13:42:08 Rollback locks table - why?
Previous Message Gurjeet Singh 2008-03-20 13:13:47 Re: Select into