Help with INSERT into 2 tables

Поиск
Список
Период
Сортировка
От gntrs@hotmail.com (Gintas)
Тема Help with INSERT into 2 tables
Дата
Msg-id 558f8e45.0111130542.1e617f99@posting.google.com
обсуждение исходный текст
Ответы 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>)
Список 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 по дате отправления:

Предыдущее
От: Martín Marqués
Дата:
Сообщение: Re: Unable to use '-' in column names in PLPGSQL
Следующее
От: Sharmad Naik
Дата:
Сообщение: Re: error in postgresql