I want to set a sequence in my table. So I listed all sequences with
SELECT c.relname
FROM pg_class c
WHERE c.relkind = 'S';
which gives me e.g.: tableName_id_seq
when I try to set the sequence using
SELECT setval("tableName_id_seq", (SELECT MAX(id) from "tableName"));
I get:
ERROR: relation "tableName_id_seq" does not exist
LINE 1: SELECT setval('tableName_id_seq', (SELECT MAX(id) from "t...
I already tried single and double quotes. Anyone any idea what to do here?
Avoid creating identifiers in camel case. It's really boring to work with it:
CREATE SEQUENCE "CamelCaseSeq";
SELECT nextval(format('%I', 'CamelCaseSeq'));
SELECT setval(format('%I', 'CamelCaseSeq'), 6666);
SELECT currval(format('%I', 'CamelCaseSeq'));
SELECT * FROM "CamelCaseSeq";
A quote from the docs:
Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other.
More info here and here.
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