Problems with double quotes in PostgreSQL SQL statements

Source: Internet
Author: User
Tags postgresql

The recent development of a Web ETL tool requires a different data source. The first time you find a double quote with PostgreSQL raises the question:

Standard SQL is case-insensitive. However, PostgreSQL allows for the use of case-sensitive definitions and reference methods for the names of objects in the database. The way to do this is to enclose the object name that you want to support in the DDL with double quotation marks.
For example, you want to create a table called AAA. If you use the Create TABLE AAA (... ), the created table is actually AAA.
If you want to create an uppercase AAA table, you need to use CREATE TABLE "AAA" (...); This double-quote method defines the object name.
The disadvantage of this writing is that the query statement must also refer to the object name in double quotation marks. For example, select * from "AAA", otherwise PostgreSQL lacks the capital to find the AAA object, and then returns the AAA non-existent error. It is important to note that not only the table can be defined and referenced, it is valid for any object in PostgreSQL (such as column name, index name, and so on).


In fact, traditional SQL is case-insensitive, so as long as DDL and DLLs manipulate database objects in a traditional way (without using double quotes) there is no problem. The problem is that if the table is created from the Pgadmin III tool of PostgreSQL, the default is to create the object in double quotes, so the DLL must also be used in the same way as double quotes. However, this is not standard, and if you access the database through some common library functions, it will not be supported.


Suggestions:
1. It is not recommended to use the Pgadmin III tool to create database objects. Or you should write the DDL statements manually.
2. It is not recommended to create case-sensitive objects in the DDL using double quotation marks.
3.PostgreSQL gives the suggestion that the SQL key word is capitalized, the other names all use lowercase.

Problems with double quotes in PostgreSQL SQL statements

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.