Skip site navigation (1) Skip section navigation (2)

Re: Need magic for inserting in 2 tables

From: Andreas <maps(dot)on(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need magic for inserting in 2 tables
Date: 2010-10-04 02:31:55
Message-ID: 4CA93C9B.7010201@gmx.net (view raw or flat)
Thread:
Lists: 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.

In response to

Responses

pgsql-sql by date

Next:From: Scott MarloweDate: 2010-10-04 02:46:03
Subject: Re: Need magic for inserting in 2 tables
Previous:From: Scott MarloweDate: 2010-10-04 00:58:13
Subject: Re: Need magic for inserting in 2 tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group