From: | Catalin CIOCOIU <catalin(dot)ciocoiu(at)inpg(dot)fr> |
---|---|
To: | "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net> |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Last ID |
Date: | 2001-03-02 17:20:05 |
Message-ID: | 3A9FD645.6FA395A@inpg.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
"Brett W. McCoy" wrote:
>
> On Fri, 2 Mar 2001, Catalin CIOCOIU wrote:
>
> > How can I get Last ID inserted ???
> > The problem is for a multiuser(symultans) database. Exist a statment SQL
> > witch get the last id inserted for a session ?
>
> currval('<seq name>') is the way to get the value that was last inserted
> into the database. However, there is no guarantee, in a multiuser
> environment, that the value you got was the value you actually used. You
> can also user last_value in an SQL statement, but you still have the
> problem of having multiple backends generating sequence values.
>
> A more reliable way is to explicitly call nextval('<seq name>') and use
> the value returned to insert into the database.
This method don't encourage using serial data type. Practically, in the
joined table I can't use "serial" data type for primary key. I nead to
use sequences by hand.
The last solution work fine, but I need a variable for store the
nextval('<seq name>').
There is not a other solution ?
>
> Please see the CREATE SEQUENCE documentation at
> http://www.postgresql.org/users-lounge/docs/7.0/user/sql-createsequence.htm
>
> -- Brett
> http://www.chapelperilous.net/~bmccoy/
> ---------------------------------------------------------------------------
> While my BRAINPAN is being refused service in BURGER KING, Jesuit
> priests are DATING CAREER DIPLOMATS!!
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-03-02 17:48:35 | Re: Last ID |
Previous Message | Brett W. McCoy | 2001-03-02 16:33:34 | Re: Last ID |