diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-04-07 12:35:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-04-07 12:35:01 +0000 |
commit | 58c11f70074708344e433080e47621091a6dcd84 (patch) | |
tree | 2589166e0e58be4947e07a956d26efa497bccaf2 /tests/dialects/test_dialect.py | |
parent | Adding upstream version 11.4.5. (diff) | |
download | sqlglot-58c11f70074708344e433080e47621091a6dcd84.tar.xz sqlglot-58c11f70074708344e433080e47621091a6dcd84.zip |
Adding upstream version 11.5.2.upstream/11.5.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_dialect.py')
-rw-r--r-- | tests/dialects/test_dialect.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py index 0805e9c..3558d62 100644 --- a/tests/dialects/test_dialect.py +++ b/tests/dialects/test_dialect.py @@ -290,6 +290,60 @@ class TestDialect(Validator): read={"postgres": "INET '127.0.0.1/32'"}, ) + def test_decode(self): + self.validate_identity("DECODE(bin, charset)") + + self.validate_all( + "SELECT DECODE(a, 1, 'one')", + write={ + "": "SELECT CASE WHEN a = 1 THEN 'one' END", + "oracle": "SELECT CASE WHEN a = 1 THEN 'one' END", + "redshift": "SELECT CASE WHEN a = 1 THEN 'one' END", + "snowflake": "SELECT CASE WHEN a = 1 THEN 'one' END", + "spark": "SELECT CASE WHEN a = 1 THEN 'one' END", + }, + ) + self.validate_all( + "SELECT DECODE(a, 1, 'one', 'default')", + write={ + "": "SELECT CASE WHEN a = 1 THEN 'one' ELSE 'default' END", + "oracle": "SELECT CASE WHEN a = 1 THEN 'one' ELSE 'default' END", + "redshift": "SELECT CASE WHEN a = 1 THEN 'one' ELSE 'default' END", + "snowflake": "SELECT CASE WHEN a = 1 THEN 'one' ELSE 'default' END", + "spark": "SELECT CASE WHEN a = 1 THEN 'one' ELSE 'default' END", + }, + ) + self.validate_all( + "SELECT DECODE(a, NULL, 'null')", + write={ + "": "SELECT CASE WHEN a IS NULL THEN 'null' END", + "oracle": "SELECT CASE WHEN a IS NULL THEN 'null' END", + "redshift": "SELECT CASE WHEN a IS NULL THEN 'null' END", + "snowflake": "SELECT CASE WHEN a IS NULL THEN 'null' END", + "spark": "SELECT CASE WHEN a IS NULL THEN 'null' END", + }, + ) + self.validate_all( + "SELECT DECODE(a, b, c)", + write={ + "": "SELECT CASE WHEN a = b OR (a IS NULL AND b IS NULL) THEN c END", + "oracle": "SELECT CASE WHEN a = b OR (a IS NULL AND b IS NULL) THEN c END", + "redshift": "SELECT CASE WHEN a = b OR (a IS NULL AND b IS NULL) THEN c END", + "snowflake": "SELECT CASE WHEN a = b OR (a IS NULL AND b IS NULL) THEN c END", + "spark": "SELECT CASE WHEN a = b OR (a IS NULL AND b IS NULL) THEN c END", + }, + ) + self.validate_all( + "SELECT DECODE(tbl.col, 'some_string', 'foo')", + write={ + "": "SELECT CASE WHEN tbl.col = 'some_string' THEN 'foo' END", + "oracle": "SELECT CASE WHEN tbl.col = 'some_string' THEN 'foo' END", + "redshift": "SELECT CASE WHEN tbl.col = 'some_string' THEN 'foo' END", + "snowflake": "SELECT CASE WHEN tbl.col = 'some_string' THEN 'foo' END", + "spark": "SELECT CASE WHEN tbl.col = 'some_string' THEN 'foo' END", + }, + ) + def test_if_null(self): self.validate_all( "SELECT IFNULL(1, NULL) FROM foo", |