Skip to content

Postgres: allow reserved keywords as bare column alias - #2491

Open
BenSatori wants to merge 3 commits into
apache:mainfrom
BenSatori:postgres-bare-keyword-column-alias
Open

BenSatori wants to merge 3 commits into
apache:mainfrom
BenSatori:postgres-bare-keyword-column-alias

Conversation

@BenSatori

Copy link
Copy Markdown
Contributor

PostgreSQL allows almost any keyword (SELECT, ANALYZE, LATERAL, AND, OR, COLLATE, ...) to be used as a bare (AS-less) column alias unless it is in a small set of keywords that require a leading AS.

See https://www.postgresql.org/docs/current/sql-keywords-appendix.html

Previously:
SELECT (SELECT c FROM tbl_name LIMIT 1) select;

(or analyze/lateral/and/or/collate)
failed to parse.

This PR fixes that

Comment thread src/dialect/postgresql.rs Outdated
Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs
PostgreSQL allows almost any keyword (SELECT, ANALYZE, LATERAL, AND, OR,
COLLATE, ...) to be used as a bare (AS-less) column alias unless it is in
a small set of keywords that require a leading AS.

See https://www.postgresql.org/docs/current/sql-keywords-appendix.html

Previously:
  SELECT (SELECT c FROM tbl_name LIMIT 1) select;
failed to parse.
@BenSatori
BenSatori force-pushed the postgres-bare-keyword-column-alias branch from 907398c to 0de43ef Compare September 14, 2026 10:21
@BenSatori

Copy link
Copy Markdown
Contributor Author

I also tested directly on pg the aliases in the tests @LucaCappelletti94 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants