Skip to content

Commit f992f84

Browse files
committed
add test
1 parent 90d2af9 commit f992f84

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_base_sql/test_select_structure.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,37 @@ def test_in_union(self):
904904
assert str(ast) == str(expected_ast)
905905
assert ast.to_tree() == expected_ast.to_tree()
906906

907+
def test_union_alias(self):
908+
sql = f'''
909+
SELECT * FROM (
910+
(
911+
SELECT col1 FROM tab1
912+
UNION
913+
SELECT col1 FROM tab2
914+
)
915+
UNION
916+
SELECT col1 FROM tab3
917+
) AS tt
918+
'''
919+
ast = parse_sql(sql)
920+
921+
expected_ast = Select(
922+
targets=[Star()],
923+
from_table=Union(
924+
left=Union(
925+
left=Select(targets=[Identifier('col1')], from_table=Identifier('tab1')),
926+
right=Select(targets=[Identifier('col1')], from_table=Identifier('tab2')),
927+
parentheses=True
928+
),
929+
right=Select(targets=[Identifier('col1')], from_table=Identifier('tab3')),
930+
parentheses=True,
931+
alias=Identifier('tt')
932+
)
933+
)
934+
935+
assert str(ast) == str(expected_ast)
936+
assert ast.to_tree() == expected_ast.to_tree()
937+
907938

908939
class TestSelectStructureNoSqlite:
909940
def test_select_from_plugins(self):

0 commit comments

Comments
 (0)