Skip to content

Commit dcc783a

Browse files
fix(clickhouse): Allow TokenType.SELECT as a Tuple field identifier (#3766)
* fix(clickhouse): Allow TokenType.SELECT as a Tuple identifier * Copy RESERVED_TOKENS only once * Update sqlglot/dialects/clickhouse.py --------- Co-authored-by: Jo <[email protected]>
1 parent 0606af6 commit dcc783a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

sqlglot/dialects/clickhouse.py

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ class Parser(parser.Parser):
332332
TokenType.SET,
333333
}
334334

335+
RESERVED_TOKENS = parser.Parser.RESERVED_TOKENS - {TokenType.SELECT}
336+
335337
AGG_FUNC_MAPPING = (
336338
lambda functions, suffixes: {
337339
f"{f}{sfx}": (f, sfx) for sfx in (suffixes + [""]) for f in functions

tests/dialects/test_clickhouse.py

+5
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ def test_clickhouse(self):
451451
self.validate_identity("ALTER TABLE visits REPLACE PARTITION ID '201901' FROM visits_tmp")
452452
self.validate_identity("ALTER TABLE visits ON CLUSTER test_cluster DROP COLUMN col1")
453453

454+
self.assertIsInstance(
455+
parse_one("Tuple(select Int64)", into=exp.DataType, read="clickhouse"), exp.DataType
456+
)
457+
454458
def test_cte(self):
455459
self.validate_identity("WITH 'x' AS foo SELECT foo")
456460
self.validate_identity("WITH ['c'] AS field_names SELECT field_names")
@@ -548,6 +552,7 @@ def test_ddl(self):
548552
self.validate_identity(
549553
"CREATE TABLE foo (x UInt32) TTL time_column + INTERVAL '1' MONTH DELETE WHERE column = 'value'"
550554
)
555+
self.validate_identity("CREATE TABLE named_tuples (a Tuple(select String, i Int64))")
551556

552557
self.validate_all(
553558
"""

0 commit comments

Comments
 (0)