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

Why Can't PostgreSQL Table or Column Names Begin with Numbers?

Mary-Kate Olsen
Release: 2024-12-22 15:54:11
Original
919 people have browsed it

Why Can't PostgreSQL Table or Column Names Begin with Numbers?

Why Can't Table or Column Names Start with Numerics?

When creating objects in PostgreSQL, such as tables or columns, it is necessary to give them names. These names must meet certain criteria, including the restriction that they cannot start with a numeric character.

Reason for the Restriction

This convention stems from the original SQL standards, which specify that identifiers (including object names) must begin with either a letter or an underscore. This design decision was primarily made to simplify parsing.

Parsing Challenges

If numeric characters were allowed as identifier starts, it would create ambiguity in the SQL syntax. For example, in the following SELECT-list clause:

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

It would be unclear whether "2e2" refers to a table name or a numeric expression, and "3.4" could potentially be interpreted as the numeric value or the table name "3" and column name "4".

Conclusion

Enforcing this restriction ensures a clear distinction between object names and other SQL elements, making the parsing process more efficient and unambiguous. While it may seem like a minor limitation, it helps maintain consistency and ease of use within the SQL language. To work around this restriction, it is possible to enclose names in double quotes, as seen in the example:

CREATE TABLE "15909434_user" ( ... )
Copy after login

The above is the detailed content of Why Can't PostgreSQL Table or Column Names Begin 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template