Re: Need magic for inserting in 2 tables - Mailing list pgsql-sql

From Andreas
Subject Re: Need magic for inserting in 2 tables
Date
Msg-id 4CA93C9B.7010201@gmx.net
Whole thread Raw
In response to Re: Need magic for inserting in 2 tables  (Scott Marlowe <scott.marlowe@gmail.com>)
Responses Re: Need magic for inserting in 2 tables  (Scott Marlowe <scott.marlowe@gmail.com>)
List pgsql-sql
Am 04.10.2010 02:58, schrieb Scott Marlowe:
>
> The same way it would use the output of a select, it's a record set.
> So it's x rows by y columns.

Then where were my insert statements wrong?
Please, look this is a simple but complete example and show me my error.

create temporary table table_1 ( id_1 serial primary key, txt  text );
create temporary table table_2 as select 42::integer as id_2;
ALTER TABLE table_2 ADD CONSTRAINT t2_pkey PRIMARY KEY( id_2 );
create temporary table t1_t2 ( fk_1 integer references table_1 ( id_1 ), 
fk_2 integer references table_2 ( id_2 ) );

--  delete from table_1;

insert into t1_t2 ( fk_1, fk_2 )    insert into table_1 ( txt )    values ( 'A' ), ( 'B' ), ( 'C' )    returning id_1,
42;

The inner insert works and dumps the inserted ids along with the 
constant which is needed in the outer insert as reference to the project.

Both inserts run together give an error.


pgsql-sql by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: Need magic for inserting in 2 tables
Next
From: Scott Marlowe
Date:
Subject: Re: Need magic for inserting in 2 tables