1

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

5
  • The error message is clear: Table/View/Alias/Whatever with name my_sequence does not exist. Maybe a typo? Commented Feb 18, 2021 at 11:53
  • @S-Man unfortunately no, I've even tried copy-pasting the name of the sequence Commented Feb 18, 2021 at 11:55
  • Wrong schema? Try my_schema.my_sequence. Commented Feb 18, 2021 at 11:59
  • That worked!! Thank you so much. However, i was under the impresion that i was already in that schema in my console, so i don't get why that happened Commented Feb 18, 2021 at 12:01
  • @S-Man post it as an answer so i can vote it Commented Feb 18, 2021 at 12:02

2 Answers 2

1

You have to define the schema you are using:

SELECT last_value FROM my_schema.my_sequence
Sign up to request clarification or add additional context in comments.

2 Comments

I haven't enough reputation so as to vote, but believe me, I really do apreciate it
There you go. Thanks!
1

Try this :

select currval('my_sequence')

OR

select currval('my_schema.my_sequence')

3 Comments

Same error, with and without the apostrophes
Did you tied currval ?
Now it does recognize the sequence, still, aonly works if i've used the sequence in the current session. Anyways, thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.