Repository navigation
Accept a non-reserved keyword as a table alias without AS - #336
Merged
git-hulk merged 3 commits intoOct 28, 2026
Merged
Conversation
`SELECT * FROM t ip` failed because any keyword after a table was refused as its alias, while ClickHouse only refuses the keywords that can follow a table (its ParserAlias::restricted_keywords). Refuse just the non-reserved ones of those here, plus LOCAL for a LOCAL JOIN, and keep COMMENT before a string as a view's trailing comment.
ClickHouse reads `t UUID 'uuid'` as a table name with its UUID, so `FROM t uuid` is a syntax error there while `FROM (SELECT 1) uuid` is an alias; refuse UUID only after a table name. Test every non-reserved keyword as an implicit table alias, and check the restricted set against ClickHouse's ParserAlias::restricted_keywords so the two cannot drift.
git-hulk
reviewed
Oct 28, 2026
git-hulk
approved these changes
Oct 28, 2026
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.
SELECT * FROM t ipfailed with<EOF> or ';' was expected, but got: "ip":parseTableExprrefused every keyword as a table alias without AS. ClickHouse refuses only the keywords that can follow a table (ParserAlias::restricted_keywords), soFROM t ip,FROM t keyandFROM (SELECT 1) ipall run there. Column aliases already work this way since #193.A keyword after a table is now its alias unless it is:
matchTokenKindas before;FROM t1 LOCAL);... FROM t COMMENT 'x'), as in ClickHouse since Fix parser treating COMMENT as implicit alias in CREATE MATERIALIZED VIEW ClickHouse/ClickHouse#110372;t UUID 'uuid'.FROM (SELECT 1) uuidstays an alias.FROM numbers(3) overfails there (checked withclickhouse local26.9).FROM t overandFROM (SELECT 1) overstay aliases.Tests:
TestNonReservedKeywordAsTableAliasWithoutAs: aliases on tables, subqueries, table functions, joins and comma joins, plus one case for each keyword that can follow a table. Each query is also formatted and parsed back.TestTableAliasWithoutAsForEveryKeyword: every non-reserved keyword after a table name.TestOverAfterTableFunctionIsNotAnAlias:FROM numbers(3) overfails.TestTableAliasRestrictedKeywordsMatchClickHouse: the restricted set must equal the non-reserved part of ClickHouse's list plus LOCAL, so a keyword added later cannot slip past it.select_table_keyword_alias_without_as.sql, with regeneratedoutput/andformat/goldens.Verification:
go test -race ./... -compatiblepasses on Go 1.27; CI covers 1.21..golangci.yml: no issues. govet's atomicalign analyzer was off, because v1.53.3 panics in it when built with Go 1.22.clickhouse local26.9 (EXPLAIN AST) agrees with every case in the new tests exceptFROM t LOCAL JOIN u, which ClickHouse reads as alias LOCAL plus a plain join.tests/queries/0_stateless, parsed with master and with this branch: 27 now parse (implicit aliases such asfirst,source,user,valuesandcomment), and no statement that parsed before fails or parses differently.