diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2023-12-10 10:45:55 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2023-12-10 10:45:55 +0000 |
commit | 02df6cdb000c8dbf739abda2af321a4f90d1b059 (patch) | |
tree | 2fc1daf848082ff67a11e60025cac260e3c318b2 /tests/test_build.py | |
parent | Adding upstream version 19.0.1. (diff) | |
download | sqlglot-upstream/20.1.0.tar.xz sqlglot-upstream/20.1.0.zip |
Adding upstream version 20.1.0.upstream/20.1.0
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'tests/test_build.py')
-rw-r--r-- | tests/test_build.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/test_build.py b/tests/test_build.py index 4dc993f..087bc7e 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -3,6 +3,7 @@ import unittest from sqlglot import ( alias, and_, + case, condition, except_, exp, @@ -77,9 +78,13 @@ class TestBuild(unittest.TestCase): (lambda: x.ilike("y"), "x ILIKE 'y'"), (lambda: x.rlike("y"), "REGEXP_LIKE(x, 'y')"), ( - lambda: exp.Case().when("x = 1", "x").else_("bar"), + lambda: case().when("x = 1", "x").else_("bar"), "CASE WHEN x = 1 THEN x ELSE bar END", ), + ( + lambda: case("x").when("1", "x").else_("bar"), + "CASE x WHEN 1 THEN x ELSE bar END", + ), (lambda: exp.func("COALESCE", "x", 1), "COALESCE(x, 1)"), (lambda: select("x"), "SELECT x"), (lambda: select("x"), "SELECT x"), @@ -614,6 +619,10 @@ class TestBuild(unittest.TestCase): "INSERT INTO tbl SELECT * FROM tbl2", ), ( + lambda: exp.insert("SELECT * FROM tbl2", "tbl", returning="*"), + "INSERT INTO tbl SELECT * FROM tbl2 RETURNING *", + ), + ( lambda: exp.insert("SELECT * FROM tbl2", "tbl", overwrite=True), "INSERT OVERWRITE TABLE tbl SELECT * FROM tbl2", ), @@ -630,6 +639,14 @@ class TestBuild(unittest.TestCase): "(x, y) IN ((1, 2), (3, 4))", "postgres", ), + ( + lambda: exp.cast_unless("CAST(x AS INT)", "int", "int"), + "CAST(x AS INT)", + ), + ( + lambda: exp.cast_unless("CAST(x AS TEXT)", "int", "int"), + "CAST(CAST(x AS TEXT) AS INT)", + ), ]: with self.subTest(sql): self.assertEqual(expression().sql(dialect[0] if dialect else None), sql) |