Re: [PGSQL 8.2.x] INSERT+INSERT

From: PFC <lists(at)peufeu(dot)com>
To: "Vincenzo Romano" <vincenzo(dot)romano(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: [PGSQL 8.2.x] INSERT+INSERT
Date: 2007-06-22 15:00:49
Message-ID: op.tubvznxjcigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> I think it would be greatly helpful if the insert...returning could be
> seen as a "select" statement and, thus, being usable in the way I
> have described. I suspect that the insert...returning is actually
> implemented as an inser plus a select.

You can create a function which does the INSERT RETURNING and returns the
result, and use this function in a subsequent INSERT.

You can also write, in plpgsql :

FOR a,b,c IN SELECT ... LOOP
INSERT INTO table1 (...) VALUES (a,b) RETURNING your_id INTO _var;
INSERT INTO table2 (...) VALUES (c , _var );
END LOOP

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-06-22 15:11:33 Re: Proposed Feature
Previous Message Bruce Momjian 2007-06-22 14:57:48 Re: Proposed Feature