Problems with capitalization in PostgreSQL

Source: Internet
Author: User
Tags postgresql

Today, I have a strange problem (actually a very basic problem).

Problem Description:

A sequence, named: sv_info_seq_id in Pgadmin, the query information_schema.sequences view also exists, the name is exactly the same, but in the reset always prompt relation does not exists, the Reset statement is

Select Setval (' sv_info_seq_id ', 1)

Troubleshooting process:

Puzzled for a long time without fruit, the execution of select Nextval (' sv_info_seq_id ') is the same as the hint relationship does not exist. When you view the build, SQL only discovers the problem, and it is created using the Create SEQUENCE "sv_info_seq_id" ...

It suddenly occurred to me that PG is case sensitive, and by default the object names are all converted to lowercase and stored in the database. If you want to keep uppercase or case-insensitive, you must enclose the object in double quotation marks and use double quotation marks. Execute again

Select Setval (' "sv_info_seq_id" ', 1) gets the correct result.

As an example:

Create sequence "Test_seq" INCREMENT 1 start 1 minvalue 1 maxvalue 10;

After execution, the name stored in the database is uppercase, and the name must also be enclosed in double quotation marks, such as

Select Nextval ("Test_seq")

Final conclusion:

Database objects as far as possible all lowercase names, do not capitalize or size mix, development, good development specifications, will avoid problems.

This article is from the "Mirror" blog, please be sure to keep this source http://383133430.blog.51cto.com/454215/1775156

Problems with capitalization in PostgreSQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.