Help with INSERT into 2 tables

From: gntrs(at)hotmail(dot)com (Gintas)
To: pgsql-sql(at)postgresql(dot)org
Subject: Help with INSERT into 2 tables
Date: 2001-11-13 13:42:08
Message-ID: 558f8e45.0111130542.1e617f99@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jason 2001-11-13 16:43:12 Insert values from one existing table into a new table.
Previous Message Carl van Tast 2001-11-13 10:26:12 Re: Is this a bug?