postgresql sequence nextval in schema

梦想与她 提交于 2019-11-30 12:30:21

问题


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 not Works:

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.


回答1:


The quoting rules are painful. I think you want:

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

to prevent case-folding of SQ_ID.




回答2:


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)


来源:https://stackoverflow.com/questions/21397601/postgresql-sequence-nextval-in-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!