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 9E2BB9FA61D for ; Wed, 5 Jul 2006 18:32:52 -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 09345-04 for ; Wed, 5 Jul 2006 18:32:41 -0300 (ADT) X-Greylist: delayed 06:47:36.38348 by SQLgrey- Received: from AMD.leals.com (215.Red-80-25-136.staticIP.rima-tde.net [80.25.136.215]) by postgresql.org (Postfix) with ESMTP id 24CB79FA4A8 for ; Wed, 5 Jul 2006 18:32:41 -0300 (ADT) Received: from amd.leals.com (AMD.leals.com [192.168.0.2]) by AMD.leals.com (Postfix) with ESMTP id B89A48D8048; Thu, 6 Jul 2006 00:07:07 +0200 (CEST) From: Davi Leal To: pgsql-sql@postgresql.org Subject: Re: Foreign Key: what value? -- currval() Date: Thu, 6 Jul 2006 00:07:06 +0200 User-Agent: KMail/1.7.2 Cc: "A. Kretschmer" References: <200607051719.27466.davi@leals.com> <20060705153415.GA15042@webserv.wug-glas.de> In-Reply-To: <20060705153415.GA15042@webserv.wug-glas.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607060007.06862.davi@leals.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/50 X-Sequence-Number: 25624 A. Kretschmer wrote: > Davi Leal folgendes: > > 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 > > currval() is your friend: > 17:33 < akretschmer> ??currval > 17:33 < pg_docbot_ads> For information about 'currval' see: > 17:33 < pg_docbot_ads> > http://www.postgresql.org/docs/current/static/functions-sequence.html It works. Thanks Andreas