Skip to content

Commit ad5b595

Browse files
authored
Feat: allow explicit aliasing in if(...) expressions (#4963)
1 parent 1f506b1 commit ad5b595

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

sqlglot/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6164,7 +6164,9 @@ def _parse_case(self) -> t.Optional[exp.Expression]:
61646164

61656165
def _parse_if(self) -> t.Optional[exp.Expression]:
61666166
if self._match(TokenType.L_PAREN):
6167-
args = self._parse_csv(self._parse_assignment)
6167+
args = self._parse_csv(
6168+
lambda: self._parse_alias(self._parse_assignment(), explicit=True)
6169+
)
61686170
this = self.validate_expression(exp.If.from_arg_list(args), args)
61696171
self._match_r_paren()
61706172
else:

tests/dialects/test_spark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def test_spark(self):
245245
"REFRESH TABLE t",
246246
)
247247

248+
self.validate_identity("IF(cond, foo AS bar, bla AS baz)")
248249
self.validate_identity("any_value(col, true)", "ANY_VALUE(col) IGNORE NULLS")
249250
self.validate_identity("first(col, true)", "FIRST(col) IGNORE NULLS")
250251
self.validate_identity("first_value(col, true)", "FIRST_VALUE(col) IGNORE NULLS")

0 commit comments

Comments
 (0)