Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 966451337BB9 for ; Sun, 3 Oct 2010 23:32:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 16131-06 for ; Mon, 4 Oct 2010 02:31:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id C67C71337B5A for ; Sun, 3 Oct 2010 23:31:52 -0300 (ADT) Received: (qmail invoked by alias); 04 Oct 2010 02:31:52 -0000 Received: from mue-88-130-59-173.dsl.tropolys.de (EHLO [192.168.0.113]) [88.130.59.173] by mail.gmx.net (mp044) with SMTP; 04 Oct 2010 04:31:52 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX19jpV8hV59judwGTyA++A44vgpbMMFUmvPNbpcBCa H3kKAPxSOeQL8A Message-ID: <4CA93C9B.7010201@gmx.net> Date: Mon, 04 Oct 2010 04:31:55 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Need magic for inserting in 2 tables References: <4CA9004E.7060106@gmx.net> <4CA9241E.9030709@gmx.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/11 X-Sequence-Number: 34662 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.