Received: from megazone.bigpanda.com ([63.150.15.178]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAFFB0m16293 for ; Thu, 15 Nov 2001 10:11:00 -0500 (EST) (envelope-from sszabo@megazone23.bigpanda.com) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 57549D5E6; Thu, 15 Nov 2001 07:11:04 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 4D06E5BE4; Thu, 15 Nov 2001 07:11:04 -0800 (PST) Date: Thu, 15 Nov 2001 07:11:04 -0800 (PST) From: Stephan Szabo To: Gintas Cc: Subject: Re: Help with INSERT into 2 tables In-Reply-To: <558f8e45.0111130542.1e617f99@posting.google.com> Message-ID: <20011115070849.N7025-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200111/211 X-Sequence-Number: 5595 On 13 Nov 2001, Gintas wrote: > I am new to SQL and don't know how to INSERT records to 2 tables. > > The first table: > > CREATE TABLE aaaa ( aaaaid SERIAL PRIMARY KEY, > text VARCHAR(20) > ); > > Second table: > > CREATE TABLE bbbb ( bbbbid SERIAL PRIMARY KEY, > aaaaid INTEGER REFERENCES aaaa (aaaaid) ON > DELETE CASCADE, > sometext VARCHAR(200) > ); > > I want to insert related records to both table. The problem is that > in order to insert record to the second table it's necessary to know > "aaaaid" field from the first table("text" is not UNIQUE): > > INSERT INTO aaaa (text) VALUES ('Some info'); > INSERT INTO bbbb (aaaaid, sometext) VALUES (?????, 'Some text'); I think you want: currval('aaaa_aaaaid_seq')