Conversation
…ithout AS Fix parsing of statements like `SELECT 1 name;` where `name` is used as a column alias without the AS keyword. PostgreSQL's keyword system has 5 categories, but our grammar only implemented 4: - reserved_keyword - unreserved_keyword - col_name_keyword - type_func_name_keyword - bare_label_keyword (NEW - orthogonal to the above) The bare_label_keyword category (455 keywords) determines which keywords can be used as column labels without the AS keyword. Keywords marked as AS_LABEL (39) require the AS keyword when used as aliases. Changes: - Updated keyword-generator to extract and generate bare_label_keyword rule - Added bare_col_label rule to PostgreSQLParser.g4 - Updated target_alias to use bare_col_label instead of identifier - Added regression test for bare column labels 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SELECT 1 name;where keywords are used as column aliases without ASbare_label_keywordcategory (455 keywords) from PostgreSQL's official grammarbare_col_labelrule and updatetarget_aliasto use itProblem
PostgreSQL supports using certain keywords as column aliases without the
ASkeyword:Our parser was rejecting
SELECT 1 name;becausetarget_aliasonly acceptedidentifier, not keywords.Solution
PostgreSQL's keyword system has 5 categories (we only had 4):
The
bare_label_keywordcategory is orthogonal to the other categories - it's defined by the 4th field in PostgreSQL'skwlist.h(BARE_LABELvsAS_LABEL).Changes
bare_label_keywordrulebare_label_keyword(auto-generated)bare_col_labelrule:identifier | bare_label_keywordtarget_aliasto usebare_col_labelinstead ofidentifierTest plan
SELECT 1 name;now parses correctlySELECT 1 year;correctly fails (requiresSELECT 1 AS year;)🤖 Generated with Claude Code