Last value inserted

From: MaRCeLO PeReiRA <gandalf_mp(at)yahoo(dot)com(dot)br>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Last value inserted
Date: 2004-11-11 12:59:16
Message-ID: 20041111125916.82486.qmail@web52703.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi guys,

I am in troubles with a SERIAL field.

I have five tables. A parent table and four child
tables. When I do the INSERT in the parent table, I
have an ID (generated) by the sequence (SERIAL field),
and I have to use this ID to reference all child
tables.

Well, once I do an INSERT in the parent table, how can
I know (for sure) which number id was generated by the
sequence?

Simple example:

------------------------------------------------------
CREATE TABLE parent(id SERIAL, descrip CHAR(50));
------------------------------------------------------

So,

------------------------------------------------------
INSERT INTO parent (descrip) VALUES ('project 1');
------------------------------------------------------

How can I now (for sure) with value was generated by
the sequence to fill the field ID?

(There is lots of users using the software at the same
time, so I am not able to use the last_value()
function on the sequence.)

Best Regards,

Marcelo Pereira
Brazil




_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Barnard 2004-11-11 14:23:18 Vacuum message
Previous Message Shridhar Daithankar 2004-11-11 12:16:25 New Opteron server from pogo linux