Home > Database > Mysql Tutorial > Why Can't PostgreSQL Table and Column Names Start with Numbers?

Why Can't PostgreSQL Table and Column Names Start with Numbers?

DDD
Release: 2024-12-30 21:35:12
Original
578 people have browsed it

Why Can't PostgreSQL Table and Column Names Start with Numbers?

Table and Column Naming Conventions in PostgreSQL: The Rationale

While attempting to create a table named "15909434_user," you encountered an error. Research revealed PostgreSQL's naming convention, which prohibits objects with names beginning with numbers. This led you to explore the reasons behind this restriction.

According to the SQL-92 standard, identifier start characters must be simple Latin letters. This convention simplifies the parsing of SQL queries, particularly when distinguishing between column names and numeric expressions in the SELECT-list clause.

Consider the following query:

SELECT 2e2 + 3.4 FROM ...
Copy after login

If numeric characters were allowed as identifier starters, the parser would struggle to determine if "2e2" is a column name or a number, and if "3.4" represents the table "3" and column "4" or the numeric value 3.4.

By adhering to the rule that identifiers must start with non-numeric characters, the parser can quickly distinguish between identifiers (column names) and numeric expressions.

Although devising a scheme allowing numeric leading characters is theoretically possible, it would likely result in more complex and obscure parsing rules.

As a result, PostgreSQL adopts the SQL convention of prohibiting table and column names from starting with numeric characters, ensuring efficient query parsing and clarity in SQL code.

The above is the detailed content of Why Can't PostgreSQL Table and Column Names Start with Numbers?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template