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 ...
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" ( ... )
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!