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

From Scott Marlowe
Subject Re: Need magic for inserting in 2 tables
Date
Msg-id AANLkTi=SR8H53MiCy9Pa2MPoLHeRyD0r3EeTYZAqMzUR@mail.gmail.com
Whole thread Raw
In response to Re: Need magic for inserting in 2 tables  (Andreas <maps.on@gmx.net>)
List pgsql-sql
On Sun, Oct 3, 2010 at 8:31 PM, Andreas <maps.on@gmx.net> wrote:
>
> 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.

Yeah, it's not capable of directly feeding the next insert like that.
You run the first insert, get the results back, then cycle through
them in your code to make the new inserts based on that.


--
To understand recursion, one must first understand recursion.


pgsql-sql by date:

Previous
From: Andreas
Date:
Subject: Re: Need magic for inserting in 2 tables
Next
From: Joshua Tolley
Date:
Subject: Re: join returns too many results...