2009/11/2 JORGE MALDONADO <jorgemal1960@gmail.com>:
> How do I use the functions to get data from sequence objects?
> For example, I need to know what is the value of a serial field after
> inserting a new record; the one assigned to the record just inserted.
>
> I have tried the psql interfase with the following:
> select currval('restaurant.ordenes_clave_seq');
> but I get a message telling me that "currval of sequence "ordenes_clave_seq"
> is not yet defined in this session.
Thats a "per session" function request...
however, if you describe the sequence, you'll see something like this:
\d dt_messages_sequence
Sequence "public.dt_messages_sequence"
Column | Type
---------------+---------
sequence_name | name
last_value | bigint
increment_by | bigint
max_value | bigint
min_value | bigint
cache_value | bigint
log_cnt | bigint
is_cycled | boolean
is_called | boolean
and then you can get the current value:
trackerData=> select last_value from dt_messages_sequence;
last_value
------------
1208
(1 row)
... however, if the sequence is being used in the session, then you
must use currval rather than the select I described above... because
it is thread-safe. This mechanism I described above may give you
something less than the current value if the sequence is in use.
>
> Please advice.
>
> Respectfully,
> Jorge Maldonado
--
Brian Modra Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/