SQL-question: returning the id of an insert querry

Поиск
Список
Период
Сортировка
От Andreas Fromm
Тема SQL-question: returning the id of an insert querry
Дата
Msg-id 3FAE171D.4050609@physik.uni-erlangen.de
обсуждение исходный текст
Ответы Re: SQL-question: returning the id of an insert querry  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Im building an user database with many tables keeping the data for the
Address, Phone numbers, etc which are referenced by a table where I keep
the single users. My question is, how do I get the "Id"-value of a newly
inserted address to store it in the referencing user table:

(a)  INSERT INTO address VALUES (....);

(b)  INSERT INTO users VALUES ( name, ... , address , ... );

where address should hold the value of the Id from the Adress table.


Do have to do an
SELECT id FROM address WHERE oid = oid_returned_by_insert(a)
or something like that after doing the insert(a) to get the correct id
value, or is there a better way to do this.

Im writing my app in Perl with DBD/DBI


Thanks in advance,

Andreas Fromm

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/rhcdPkvkZVZzNY0RApmDAJ4k4MY/zKvH2862MuHSIjDtsmIs3QCfRzaR
0zDc1bIQAOMpLurvRZ2V8JY=
=kgaA
-----END PGP SIGNATURE-----


В списке pgsql-general по дате отправления:

Предыдущее
От: Rajesh Kumar Mallah
Дата:
Сообщение: Re: Problem in restoring data [SOLVED ]
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: SQL-question: returning the id of an insert querry