83

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.

3 Answers 3

165

The quoting rules are painful. I think you want:

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

to prevent case-folding of SQ_ID.

Sign up to request clarification or add additional context in comments.

2 Comments

SQL does not "case fold" in SQL the double quote is for denoting db objects seq and table names the single quote is for denoting static string values . They are not interchangeable. select "field" from "table" where "field" = 'value';
Of all the combinations of single and double quotes I tried, this would have been my last guess.
12
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)

Comments

3
SELECT nextval('"your_schema_name"."your_sequence_name"')

works for me !!

1 Comment

+100, this is the correct answer!

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.