Are number-only column names are allowed?

As the thread says. Can we use number only column names?

Yes. But they can be confusing!

CREATE TABLE "mehmeh" (
    a1 INT, 
    "1" INT
);

INSERT INTO "mehmeh" VALUES (100, 1);
INSERT INTO "mehmeh" VALUES (50, 20);

SELECT * FROM "mehmeh" ORDER BY a1;
SELECT * FROM "mehmeh" ORDER BY "1";
SELECT * FROM "mehmeh" ORDER BY "1";

In the ORDER BY, the last statement is referring to the column named “1” as I am using quotes, but the other statements are using columns by position.

It also messes a bit with the autoaliases of joined columns, as in

SELECT * 
FROM mehmeh m1 
CROSS JOIN mehmeh m2 
CROSS JOIN mehmeh m3;

image

Also, for a full breakdown of allowable column names, check out the doc:

1 Like