pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas <maps.on@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: Need magic for inserting in 2 tables
Date: Mon, 04 Oct 2010 04:31:55 +0200
Message-ID: <4CA93C9B.7010201@gmx.net> (raw)
In-Reply-To: <AANLkTi=8cS5ODYOauMFHdKfw=6iZnp8GYCMhmHpVvavm@mail.gmail.com>
References: <4CA9004E.7060106@gmx.net>
	<AANLkTinibE8HA3nipALO_aGsgxYDACf0xokUiPJrq5bz@mail.gmail.com>
	<4CA9241E.9030709@gmx.net>
	<AANLkTi=8cS5ODYOauMFHdKfw=6iZnp8GYCMhmHpVvavm@mail.gmail.com>

  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.



view thread (6+ messages)  latest in thread

Message-ID: <4CA93C9B.7010201@gmx.net>
Permalink:  ../4CA93C9B.7010201@gmx.net/
Also on:    postgresql.org/message-id/4CA93C9B.7010201@gmx.net

 · 

reply

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: maps.on@gmx.net
  Subject: Re: Need magic for inserting in 2 tables
  In-Reply-To: <4CA93C9B.7010201@gmx.net>

* 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