summaryrefslogtreecommitdiffstats
path: root/tests/test_build.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:44:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-10 06:44:58 +0000
commitbeba715b97dd2349e01dde9b077d2535680ebdca (patch)
tree0c54accb48c28eb54d2f48f88d149492717b30e5 /tests/test_build.py
parentReleasing debian version 11.7.1-1. (diff)
downloadsqlglot-beba715b97dd2349e01dde9b077d2535680ebdca.tar.xz
sqlglot-beba715b97dd2349e01dde9b077d2535680ebdca.zip
Merging upstream version 12.2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_build.py')
-rw-r--r--tests/test_build.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index c4b97ce..509b857 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -19,6 +19,11 @@ from sqlglot import (
class TestBuild(unittest.TestCase):
def test_build(self):
x = condition("x")
+ x_plus_one = x + 1
+
+ # Make sure we're not mutating x by changing its parent to be x_plus_one
+ self.assertIsNone(x.parent)
+ self.assertNotEqual(id(x_plus_one.this), id(x))
for expression, sql, *dialect in [
(lambda: x + 1, "x + 1"),
@@ -51,6 +56,7 @@ class TestBuild(unittest.TestCase):
(lambda: x.neq(1), "x <> 1"),
(lambda: x.isin(1, "2"), "x IN (1, '2')"),
(lambda: x.isin(query="select 1"), "x IN (SELECT 1)"),
+ (lambda: x.between(1, 2), "x BETWEEN 1 AND 2"),
(lambda: 1 + x + 2 + 3, "1 + x + 2 + 3"),
(lambda: 1 + x * 2 + 3, "1 + (x * 2) + 3"),
(lambda: x * 1 * 2 + 3, "(x * 1 * 2) + 3"),
@@ -137,10 +143,14 @@ class TestBuild(unittest.TestCase):
"SELECT x, y, z, a FROM tbl GROUP BY x, y, z, a",
),
(
- lambda: select("x").distinct(True).from_("tbl"),
+ lambda: select("x").distinct("a", "b").from_("tbl"),
+ "SELECT DISTINCT ON (a, b) x FROM tbl",
+ ),
+ (
+ lambda: select("x").distinct(distinct=True).from_("tbl"),
"SELECT DISTINCT x FROM tbl",
),
- (lambda: select("x").distinct(False).from_("tbl"), "SELECT x FROM tbl"),
+ (lambda: select("x").distinct(distinct=False).from_("tbl"), "SELECT x FROM tbl"),
(
lambda: select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl"),
"SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z",
@@ -583,6 +593,11 @@ class TestBuild(unittest.TestCase):
"DELETE FROM tbl WHERE x = 1 RETURNING *",
"postgres",
),
+ (
+ lambda: exp.convert((exp.column("x"), exp.column("y"))).isin((1, 2), (3, 4)),
+ "(x, y) IN ((1, 2), (3, 4))",
+ "postgres",
+ ),
]:
with self.subTest(sql):
self.assertEqual(expression().sql(dialect[0] if dialect else None), sql)