Juan Cruz Carrau
Juan Cruz Carrau

Reputation: 307

Error when calling for last value in sequence in PostgreSQL

I'm trying to get the last value of a sequence in my database, and acording to what i found, the query should be done like this: SELECT last_value FROM my_sequence. However, when i hit enter, the only thing I get in the console is:

ERROR:  relation "my_sequence" does not exist
LINE 1: select last_value from my_sequence;
                               ^

Any help?


Edit: the sequence does exist, for I do get the name of it when I list all sequences

Upvotes: 1

Views: 494

Answers (2)

S-Man
S-Man

Reputation: 23686

You have to define the schema you are using:

SELECT last_value FROM my_schema.my_sequence

Upvotes: 1

Vinay Hegde
Vinay Hegde

Reputation: 1460

Try this :

select currval('my_sequence')

OR

select currval('my_schema.my_sequence')

Upvotes: 1

Related Questions