Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The problem of capitalization in postgresql

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report