The problem of capitalization in postgresql
We have a strange problem today (it's actually a very basic problem). Record it.
Problem description:
A sequence with the name: SV_INFO_SEQ_id exists in PGAdmin, and the query information_schema.sequences view also exists, with exactly the same name, but always prompts relation does not exists when resetting, and the reset statement is
Select setval ('SV_INFO_SEQ_id',1)
Troubleshooting process:
Confused for a long time to no avail, the implementation of select nextval ('SV_INFO_SEQ_id') is the same hint relationship does not exist. SQL found the problem when checking the establishment, using CREATE SEQUENCE "SV_INFO_SEQ_id" when setting up.
It suddenly occurred to me that PG is case-sensitive and by default all object names are converted to lowercase and stored in the database. If you want to keep uppercase or mixed case, you must enclose the object name in double quotes and use it in double quotes. Execute again
Select setval ('"SV_INFO_SEQ_id", 1) gets the correct result.
For example:
Create sequence "TEST_SEQ" INCREMENT 1 start 1 minvalue 1 maxvalue 10
After execution, uppercase names are stored in the database, and names must be enclosed in double quotation marks when used, such as
SELECT NEXTVAL ("TEST_SEQ")
Finally, the conclusion:
Database objects as far as possible to use all lowercase names, do not uppercase and do not mix case, the development of good development norms, there must be problems.