X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E44B99FA65C for ; Wed, 5 Jul 2006 12:16:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 84374-03 for ; Wed, 5 Jul 2006 12:16:32 -0300 (ADT) X-Greylist: delayed 00:31:09.640747 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 3E82B9FB1BA for ; Wed, 5 Jul 2006 12:16:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from AMD.leals.com (215.Red-80-25-136.staticIP.rima-tde.net [80.25.136.215]) by svr4.postgresql.org (Postfix) with ESMTP id 7BEB05AF07A for ; Wed, 5 Jul 2006 14:45:10 +0000 (GMT) Received: from amd.leals.com (AMD.leals.com [192.168.0.2]) by AMD.leals.com (Postfix) with ESMTP id 82400E300DC for ; Wed, 5 Jul 2006 17:19:28 +0200 (CEST) From: Davi Leal To: pgsql-sql@postgresql.org Subject: Foreign Key: what value? Date: Wed, 5 Jul 2006 17:19:26 +0200 User-Agent: KMail/1.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607051719.27466.davi@leals.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/42 X-Sequence-Number: 25616 Hi, How to know the value which I must set in the foreign key field?. I have two tables: CREATE TABLE AAAAAA ( Id SERIAL PRIMARY KEY, data char(9) ); CREATE TABLE BBBBBB ( BBBBBB_Id integer REFERENCES AAAAAA(Id) NOT NULL, field char(5) ); I insert a register on table AAAAAA, INSERT INTO AAAAAA (data) VALUES ('123456789'); and then, I want to insert a related register in table BBBBBB, but I do not know how get the proper value to the Foreign key BBBBBB_Id. Note that a lot of client are inserting at the same time on the AAAAAA table, so I can not just get the greater value of AAAAAA.Id Maybe using transactions ?. Any tip, URI, ... will be welcome. INSERT INTO BBBBBB (BBBBBB_Id, field) VALUES (??????,'12345'); Regards, Davi