Help with INSERT into 2 tables - Mailing list pgsql-sql

From gntrs@hotmail.com (Gintas)
Subject Help with INSERT into 2 tables
Date
Msg-id 558f8e45.0111130542.1e617f99@posting.google.com
Whole thread Raw
Responses Re: Help with INSERT into 2 tables  (Jeff Eckermann <jeff_eckermann@yahoo.com>)
Re: Help with INSERT into 2 tables  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Re: Help with INSERT into 2 tables  (Roland Roberts <roland@astrofoto.org>)
Re: Help with INSERT into 2 tables  ("Andrew G. Hammond" <drew@xyzzy.dhs.org>)
List pgsql-sql
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');

How is it possible to do that?
(I am inserting this from JAVA).

Thanks for help.



Gintaras


pgsql-sql by date:

Previous
From: Martín Marqués
Date:
Subject: Re: Unable to use '-' in column names in PLPGSQL
Next
From: Sharmad Naik
Date:
Subject: Re: error in postgresql