1
votes

I'm trying to use

SELECT currval('myTable_Orderid_seq');

I got error: currval not supported.

Any work around this is much appreciated. I need to use currval for each users' session in a multi user environment.

1
You can only call currval() if you called nextval() before that. And please upgrade to a supported version now - a_horse_with_no_name
@ a_horse_with_no_name- ty for your comment. I could use nextval w/o an error but i get the same error for CURRVAL. I wish it was on my hand to upgrade to the latest version. That's why i need a work around. - Nemo
Again: you must call currval() before you call nextval() in the same session - a_horse_with_no_name
When you say "PostgreSQL 8.2.15" am I correct in guessing that you really mean "Greenplum Database 4.x" or "Amazon Redshift" or "ParAccel" or something like that, some PostgreSQL fork? - Craig Ringer

1 Answers

3
votes

If currval is not available (yet) in the session you can do this:

select last_value from myTable_Orderid_seq

From the doc: http://www.postgresql.org/docs/current/static/sql-createsequence.html

Although you cannot update a sequence directly, you can use a query like:

SELECT * FROM name;

to examine the parameters and current state of a sequence. In particular, the last_value field of the sequence shows the last value allocated by any session. (Of course, this value might be obsolete by the time it's printed, if other sessions are actively doing nextval calls.)