Re: currval question

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Andy Kriger <akriger(at)greaterthanone(dot)com>, Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: currval question
Date: 2002-09-16 22:23:30
Message-ID: 25201347.1032222210@liza
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Andy,

this is AFAIK on a per transaction basis.

HTH
Tino Wildenhain

PS: I often use a plpsql script for creating table entrys, this helps if
you have many foreign keys and need some checks and the last id too. It
looks roughly like this:

CREATE FUNCTION ...

nextid=nextval(''sequence'');

insert into table ... (nextid, ... ) ;

return nextid;

this way you can use the function in another insert, immediately using its
return
value for insert in the other table.

--On Montag, 16. September 2002 18:14 -0400 Andy Kriger
<akriger(at)greaterthanone(dot)com> wrote:

> I am trying to get the last value updated by an column auto-incrementing
> with nextval(). In MySQL, you'd use LAST_INSERT_ID() - in Postgre,
> currval() appears to do the trick.
>
> Is this maintained on a per-connection basis? For example, user A inserts
> and the nextval() updates to 5, user B does 2 inserts, updating nextval()
> to 7. When user A calls currval() they should get 5 if the updates are
> per-cnx. What does psql do under the hood here?
>
> thx
> a
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Garo Hussenjian 2002-09-16 22:34:05 Re: currval question
Previous Message Tino Wildenhain 2002-09-16 22:18:40 Re: question regarding regular expressions