Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql sequence nextval in schema

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.

like image 386
carlos Avatar asked Jan 28 '14 05:01

carlos


People also ask

How do you select a Nextval in a sequence?

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.

What is Nextval in Postgres?

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.

How do I find the sequence number in PostgreSQL?

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.


1 Answers

The quoting rules are painful. I think you want:

SELECT nextval('foo."SQ_ID"'); 

to prevent case-folding of SQ_ID.

like image 76
Craig Ringer Avatar answered Oct 06 '22 06:10

Craig Ringer