Summary
In the clickhouse dialect, SHOW and EXPLAIN statements parse to exp.Command — sqlglot's catch-all for syntax it can't recognise — rather than to dedicated AST nodes. This makes them indistinguishable from genuinely-unknown statements like SYSTEM, RENAME, ATTACH, OPTIMIZE, etc., which also fall back to Command.
Reproduction (sqlglot 30.6.0)
import sqlglot
for s in ["SHOW TABLES",
"SHOW CREATE TABLE t",
"EXPLAIN SELECT 1",
"EXPLAIN ESTIMATE SELECT 1"]:
parsed = sqlglot.parse(s, dialect="clickhouse")
print(s, "->", [type(p).__name__ for p in parsed])
Output:
'SHOW TABLES' contains unsupported syntax. Falling back to parsing as a 'Command'.
'SHOW CREATE TABLE t' contains unsupported syntax. Falling back to parsing as a 'Command'.
'EXPLAIN SELECT 1' contains unsupported syntax. Falling back to parsing as a 'Command'.
'EXPLAIN ESTIMATE SELECT 1' contains unsupported syntax. Falling back to parsing as a 'Command'.
SHOW TABLES -> ['Command']
SHOW CREATE TABLE t -> ['Command']
EXPLAIN SELECT 1 -> ['Command']
EXPLAIN ESTIMATE SELECT 1 -> ['Command']
For comparison, several other dialects do produce dedicated nodes for SHOW / EXPLAIN (e.g. exp.Show, exp.Explain).
Why it matters
In a downstream project we use sqlglot's ClickHouse dialect to validate that user-submitted SQL is read-only — accept SELECT / DESCRIBE, reject everything else. Because SHOW and EXPLAIN parse to the same Command node as SYSTEM / RENAME / ATTACH / OPTIMIZE, we can't safely allow them: accepting Command would also accept the write-capable statements. So we currently reject SHOW and EXPLAIN despite ClickHouse considering them read-only operations.
Folks doing access-control / SQL-firewall use cases with the ClickHouse dialect probably hit the same wall.
Suggested fix direction
Add ClickHouse-dialect parser support for SHOW and EXPLAIN so they produce exp.Show / exp.Explain (or dialect-specific subclasses) instead of Command. Both statements are well-defined in the ClickHouse docs — the grammar shouldn't be too painful, and dedicated nodes would unblock several validation/transformation use cases.
Happy to put up a PR if a maintainer can sketch the preferred shape.
Summary
In the
clickhousedialect,SHOWandEXPLAINstatements parse toexp.Command— sqlglot's catch-all for syntax it can't recognise — rather than to dedicated AST nodes. This makes them indistinguishable from genuinely-unknown statements likeSYSTEM,RENAME,ATTACH,OPTIMIZE, etc., which also fall back toCommand.Reproduction (sqlglot 30.6.0)
Output:
For comparison, several other dialects do produce dedicated nodes for
SHOW/EXPLAIN(e.g.exp.Show,exp.Explain).Why it matters
In a downstream project we use sqlglot's ClickHouse dialect to validate that user-submitted SQL is read-only — accept
SELECT/DESCRIBE, reject everything else. BecauseSHOWandEXPLAINparse to the sameCommandnode asSYSTEM/RENAME/ATTACH/OPTIMIZE, we can't safely allow them: acceptingCommandwould also accept the write-capable statements. So we currently rejectSHOWandEXPLAINdespite ClickHouse considering them read-only operations.Folks doing access-control / SQL-firewall use cases with the ClickHouse dialect probably hit the same wall.
Suggested fix direction
Add ClickHouse-dialect parser support for
SHOWandEXPLAINso they produceexp.Show/exp.Explain(or dialect-specific subclasses) instead ofCommand. Both statements are well-defined in the ClickHouse docs — the grammar shouldn't be too painful, and dedicated nodes would unblock several validation/transformation use cases.Happy to put up a PR if a maintainer can sketch the preferred shape.