pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Davi Leal <davi@leals.com>
To: pgsql-sql@postgresql.org
Cc: A. Kretschmer <andreas.kretschmer@schollglas.com>
Subject: Re: Foreign Key: what value? -- currval()
Date: Thu, 6 Jul 2006 00:07:06 +0200
Message-ID: <200607060007.06862.davi@leals.com> (raw)
In-Reply-To: <20060705153415.GA15042@webserv.wug-glas.de>
References: <200607051719.27466.davi@leals.com>
	<20060705153415.GA15042@webserv.wug-glas.de>

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



Message-ID: <200607060007.06862.davi@leals.com>
Permalink:  ../200607060007.06862.davi@leals.com/
Also on:    postgresql.org/message-id/200607060007.06862.davi@leals.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: davi@leals.com, andreas.kretschmer@schollglas.com
  Subject: Re: Foreign Key: what value? -- currval()
  In-Reply-To: <200607060007.06862.davi@leals.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox