I have a sequence on postgresql 9.3 inside a schema.
I can do this:
SELECT last_value, increment_by from foo."SQ_ID";`
last_value | increment_by ------------+-------------- 1 | 1 (1 fila)
But this doesn't work:
SELECT nextval('foo.SQ_ID');
ERROR: no existe la relación «foo.sq_id» LÍNEA 1: SELECT nextval('foo.SQ_ID');
What is wrong ?
It says that not exist the relation foo.sq_id
, but it exists.
To use NEXTVAL or CURRVAL with a sequence, you must have the Select privilege on the sequence or have the DBA privilege on the database.
NEXTVAL is a function to get the next value from a sequence. Sequence is an object which returns ever-increasing numbers, different for each call, regardless of transactions etc. Each time you call NEXTVAL , you get a different number. This is mainly used to generate surrogate primary keys for you tables.
CREATE SEQUENCE creates a new sequence number generator. This involves creating and initializing a new special single-row table with the name name . The generator will be owned by the user issuing the command. If a schema name is given then the sequence is created in the specified schema.
The quoting rules are painful. I think you want:
SELECT nextval('foo."SQ_ID"');
to prevent case-folding of SQ_ID
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With