Get the App
SLTechnology News&Howtos  ›  Database  › 

The problem of capitalization in postgresql

Shulou Source: shulou.com Published: 2022-06-01 08:39:19 10月27日 Update

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.

Tags: Question name uppercase size object quotation mark data database name lowercase development hint middle look confusion example again basic that is form situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi OPPO Reno Shulou Information Shulou Technology