Re: Foreign Key: what value? - Mailing list pgsql-sql

From A. Kretschmer
Subject Re: Foreign Key: what value?
Date
Msg-id 20060705153415.GA15042@webserv.wug-glas.de
Whole thread Raw
In response to Foreign Key: what value?  (Davi Leal <davi@leals.com>)
Responses Re: Foreign Key: what value? -- currval()
List pgsql-sql
am  05.07.2006, um 17:19:26 +0200 mailte 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


HTH, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47215,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net===    Schollglas Unternehmensgruppe    === 


pgsql-sql by date:

Previous
From: Davi Leal
Date:
Subject: Foreign Key: what value?
Next
From: Erik Jones
Date:
Subject: Problem with array subscripts in plpgsql trigger function