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.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)