Re: [Q] Sequences, last_value and inserts - Mailing list pgsql-general

From Gregory Wood
Subject Re: [Q] Sequences, last_value and inserts
Date
Msg-id 01f101c281e7$fbf65ad0$7889ffcc@comstock.com
Whole thread Raw
In response to Re: [Q] Sequences, last_value and inserts  ("Marie G. Tuite" <marie.tuite@edisonaffiliates.com>)
List pgsql-general
> select last_value from domain_info_tbl_key_seq;
>
> This returns the same value as currval.

In most cases, yes. However:

"Also, last_value will reflect the latest value reserved by any backend,
whether or not it has yet been returned by nextval."

http://www.postgresql.org/idocs/index.php?sql-createsequence.html

It is possible that someone else has changed the sequence value before you
read it, meaning you will not get the value you just inserted (like you
would with currval), but the value of the *other* insert.

This is precisely the problem that the original question was posed to avoid.

Greg



pgsql-general by date:

Previous
From: "Marie G. Tuite"
Date:
Subject: Re: [Q] Sequences, last_value and inserts
Next
From: "Paul Ottar Tornes"
Date:
Subject: Norwegian Letters