Re: Need magic for inserting in 2 tables

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need magic for inserting in 2 tables
Date: 2010-10-04 02:46:03
Message-ID: AANLkTi=SR8H53MiCy9Pa2MPoLHeRyD0r3EeTYZAqMzUR@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Oct 3, 2010 at 8:31 PM, Andreas <maps(dot)on(at)gmx(dot)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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joshua Tolley 2010-10-04 13:24:39 Re: join returns too many results...
Previous Message Andreas 2010-10-04 02:31:55 Re: Need magic for inserting in 2 tables