Re: Foreign Key: what value? -- currval()

From: Davi Leal <davi(at)leals(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Subject: Re: Foreign Key: what value? -- currval()
Date: 2006-07-05 22:07:06
Message-ID: 200607060007.06862.davi@leals.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Keith Worthington 2006-07-06 04:19:54 week ending
Previous Message Erik Jones 2006-07-05 18:10:53 Re: Problem with array subscripts in plpgsql trigger function