[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-sql
Subject:    Re: [SQL] Need magic for inserting in 2 tables
From:       Scott Marlowe <scott.marlowe () gmail ! com>
Date:       2010-10-04 2:46:03
Message-ID: AANLkTi=SR8H53MiCy9Pa2MPoLHeRyD0r3EeTYZAqMzUR () mail ! gmail ! com
[Download RAW message or body]

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.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic