Skip to content

Commit 9a78fbc

Browse files
fix is_alias_without_as logical error (#523)
1 parent 504f6aa commit 9a78fbc

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

sql_metadata/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def is_alias_without_as(self) -> bool:
187187
"""
188188
return (
189189
self.next_token.normalized in [",", "FROM"]
190-
and self.previous_token.normalized not in [",", ".", "(", "SELECT"]
190+
and self.previous_token.normalized not in ["*", ",", ".", "(", "SELECT"]
191191
and not self.previous_token.is_keyword
192192
and (
193193
self.last_keyword_normalized == "SELECT"

test/test_column_aliases.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,15 @@ def test_cast_in_select_with_function():
186186
"datekey": "testdb.test_table.date",
187187
"starttimekey": "testdb.test_table.starttime",
188188
}
189+
190+
191+
def test_nested_function():
192+
query = """
193+
SELECT a * b
194+
FROM c
195+
WHERE b = (SELECT MAX(b) FROM c);
196+
"""
197+
parser = Parser(query)
198+
199+
assert parser.columns == ["a", "b"]
200+
assert parser.tables == ["c"]

0 commit comments

Comments
 (0)