Skip to content

Commit

Permalink
fix is_alias_without_as logical error
Browse files Browse the repository at this point in the history
  • Loading branch information
MiuNice authored and wangyuhang committed Aug 22, 2024
1 parent 504f6aa commit c9beded
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sql_metadata/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def is_alias_without_as(self) -> bool:
"""
return (
self.next_token.normalized in [",", "FROM"]
and self.previous_token.normalized not in [",", ".", "(", "SELECT"]
and self.previous_token.normalized not in ["*", ",", ".", "(", "SELECT"]
and not self.previous_token.is_keyword
and (
self.last_keyword_normalized == "SELECT"
Expand Down
12 changes: 12 additions & 0 deletions test/test_column_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,15 @@ def test_cast_in_select_with_function():
"datekey": "testdb.test_table.date",
"starttimekey": "testdb.test_table.starttime",
}


def test_nested_function():
query = """
SELECT a * b
FROM c
WHERE b = (SELECT MAX(b) FROM c);
"""
parser = Parser(query)

assert parser.columns == ["a", "b"]
assert parser.tables == ["c"]

0 comments on commit c9beded

Please sign in to comment.