File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
908939class TestSelectStructureNoSqlite :
909940 def test_select_from_plugins (self ):
You can’t perform that action at this time.
0 commit comments