2009/11/12 A. Kretschmer <andreas.kretschmer@schollglas.com>:
> Hi,
>
> just to be sure, it is still (8.4) not possible to use RETURNING within an
> other INSERT?
>
> To show what i mean:
>
> test=*# insert into foo2 (id1, id2) (insert into foo(n) values ('a'),('b'),('c') returning currval('some_sequence'),
id);
> ERROR: syntax error at or near "insert"
> LINE 1: insert into foo2 (id1, id2) (insert into foo(n) values ('a')...
>
> I know, it is intended in 8.5 with the 'WITH' - clause, but not yet in 8.4, right?
>
> (and there are no other RDBMS which can do that?)
Well there is a little trik in actual versions...
use these options:
\a
\t
\o /tmp/archivo.csv
then
DELETE FROM tabla WHERE entero =13 RETURNING *;
(remember that you can throught this query from shell command line, with
psql options)
(next step, delete the last line of the file archivo.csv: DELETE 9890)
create a clon - void table (this will be your log table, if you have
already created this
, avoid this step):
postgres=# CREATE TABLE tabla_2 AS SELECT * FROM tabla WHERE 1=0;
SELECT
Then you can go with this
postgres=# COPY tabla_2 FROM '/tmp/returnes.csv' DELIMITER '|';
COPY 19780
postgres=# SELECT * from tabla_2 limit 1;
entero
--------
13
(1 row)
Obviusly, you can automatize these steps in a shell script.
Hope you enjoy it.
--
Emanuel Calvo Franco
DBA at: www.siu.edu.ar
www.emanuelcalvofranco.com.ar