postgresql sequence nextval in schema

PostgresqlPostgresql 9.3

Postgresql Problem Overview


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.

Postgresql Solutions


Solution 1 - Postgresql

The quoting rules are painful. I think you want:

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

to prevent case-folding of SQ_ID.

Solution 2 - Postgresql

SELECT last_value, increment_by from "other_schema".id_seq;

for adding a seq to a column where the schema is not public try this.

nextval('"other_schema".id_seq'::regclass)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncarlosView Question on Stackoverflow
Solution 1 - PostgresqlCraig RingerView Answer on Stackoverflow
Solution 2 - PostgresqlRaghulan GowthamanView Answer on Stackoverflow