summaryrefslogtreecommitdiffstats
path: root/tests/test_build.py
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2023-12-10 10:45:55 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2023-12-10 10:45:55 +0000
commit02df6cdb000c8dbf739abda2af321a4f90d1b059 (patch)
tree2fc1daf848082ff67a11e60025cac260e3c318b2 /tests/test_build.py
parentAdding upstream version 19.0.1. (diff)
downloadsqlglot-02df6cdb000c8dbf739abda2af321a4f90d1b059.tar.xz
sqlglot-02df6cdb000c8dbf739abda2af321a4f90d1b059.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.py19
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)