summaryrefslogtreecommitdiffstats
path: root/tests/test_build.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build.py')
-rw-r--r--tests/test_build.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index b5d657c..fa9e7f8 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -1,6 +1,19 @@
import unittest
-from sqlglot import and_, condition, exp, from_, not_, or_, parse_one, select
+from sqlglot import (
+ alias,
+ and_,
+ condition,
+ except_,
+ exp,
+ from_,
+ intersect,
+ not_,
+ or_,
+ parse_one,
+ select,
+ union,
+)
class TestBuild(unittest.TestCase):
@@ -320,6 +333,54 @@ class TestBuild(unittest.TestCase):
lambda: exp.update("tbl", {"x": 1}, from_="tbl2"),
"UPDATE tbl SET x = 1 FROM tbl2",
),
+ (
+ lambda: union("SELECT * FROM foo", "SELECT * FROM bla"),
+ "SELECT * FROM foo UNION SELECT * FROM bla",
+ ),
+ (
+ lambda: parse_one("SELECT * FROM foo").union("SELECT * FROM bla"),
+ "SELECT * FROM foo UNION SELECT * FROM bla",
+ ),
+ (
+ lambda: intersect("SELECT * FROM foo", "SELECT * FROM bla"),
+ "SELECT * FROM foo INTERSECT SELECT * FROM bla",
+ ),
+ (
+ lambda: parse_one("SELECT * FROM foo").intersect("SELECT * FROM bla"),
+ "SELECT * FROM foo INTERSECT SELECT * FROM bla",
+ ),
+ (
+ lambda: except_("SELECT * FROM foo", "SELECT * FROM bla"),
+ "SELECT * FROM foo EXCEPT SELECT * FROM bla",
+ ),
+ (
+ lambda: parse_one("SELECT * FROM foo").except_("SELECT * FROM bla"),
+ "SELECT * FROM foo EXCEPT SELECT * FROM bla",
+ ),
+ (
+ lambda: parse_one("(SELECT * FROM foo)").union("SELECT * FROM bla"),
+ "(SELECT * FROM foo) UNION SELECT * FROM bla",
+ ),
+ (
+ lambda: parse_one("(SELECT * FROM foo)").union("SELECT * FROM bla", distinct=False),
+ "(SELECT * FROM foo) UNION ALL SELECT * FROM bla",
+ ),
+ (
+ lambda: alias(parse_one("LAG(x) OVER (PARTITION BY y)"), "a"),
+ "LAG(x) OVER (PARTITION BY y) AS a",
+ ),
+ (
+ lambda: alias(parse_one("LAG(x) OVER (ORDER BY z)"), "a"),
+ "LAG(x) OVER (ORDER BY z) AS a",
+ ),
+ (
+ lambda: alias(parse_one("LAG(x) OVER (PARTITION BY y ORDER BY z)"), "a"),
+ "LAG(x) OVER (PARTITION BY y ORDER BY z) AS a",
+ ),
+ (
+ lambda: alias(parse_one("LAG(x) OVER ()"), "a"),
+ "LAG(x) OVER () AS a",
+ ),
]:
with self.subTest(sql):
self.assertEqual(expression().sql(dialect[0] if dialect else None), sql)