Skip to content

Commit bb4f428

Browse files
committed
Feat: bubble up comments nested under a Bracket, fixes #5131
1 parent e164b96 commit bb4f428

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

sqlglot/parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6234,7 +6234,12 @@ def _parse_bracket(self, this: t.Optional[exp.Expression] = None) -> t.Optional[
62346234
expressions = apply_index_offset(
62356235
this, expressions, -self.dialect.INDEX_OFFSET, dialect=self.dialect
62366236
)
6237-
this = self.expression(exp.Bracket, this=this, expressions=expressions)
6237+
this = self.expression(
6238+
exp.Bracket,
6239+
this=this,
6240+
expressions=expressions,
6241+
comments=this.pop_comments(),
6242+
)
62386243

62396244
self._add_comments(this)
62406245
return self._parse_bracket(this)

tests/fixtures/pretty.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,15 @@ ON t.id = s.id
457457
WHEN MATCHED THEN UPDATE SET
458458
status = s.status,
459459
amount = s.amount;
460+
461+
SELECT
462+
id,
463+
-- SUM(total) as all_that,
464+
ARRAY_AGG(foo)[0][0] AS first_foo,
465+
FROM facts
466+
GROUP BY all;
467+
SELECT
468+
id,
469+
ARRAY_AGG(foo)[0][0] AS first_foo /* SUM(total) as all_that, */
470+
FROM facts
471+
GROUP BY ALL;

0 commit comments

Comments
 (0)