summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_redshift.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-10 09:23:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-10 09:23:46 +0000
commit5dde903f4f6659e384287a3e508b9f369c5a2ba3 (patch)
tree05cd2920d82f0023f6ac695dbb6eaeef64608401 /tests/dialects/test_redshift.py
parentAdding upstream version 17.9.1. (diff)
downloadsqlglot-5dde903f4f6659e384287a3e508b9f369c5a2ba3.tar.xz
sqlglot-5dde903f4f6659e384287a3e508b9f369c5a2ba3.zip
Adding upstream version 17.11.0.upstream/17.11.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_redshift.py')
-rw-r--r--tests/dialects/test_redshift.py43
1 files changed, 29 insertions, 14 deletions
diff --git a/tests/dialects/test_redshift.py b/tests/dialects/test_redshift.py
index 90c953f..96e9e20 100644
--- a/tests/dialects/test_redshift.py
+++ b/tests/dialects/test_redshift.py
@@ -5,15 +5,16 @@ class TestRedshift(Validator):
dialect = "redshift"
def test_redshift(self):
- self.validate_identity("SELECT * FROM #x")
- self.validate_identity("SELECT INTERVAL '5 day'")
- self.validate_identity("foo$")
- self.validate_identity("$foo")
-
+ self.validate_all(
+ "SELECT INTERVAL '5 days'",
+ read={
+ "": "SELECT INTERVAL '5' days",
+ },
+ )
self.validate_all(
"SELECT ADD_MONTHS('2008-03-31', 1)",
write={
- "redshift": "SELECT DATEADD(month, 1, '2008-03-31')",
+ "redshift": "SELECT DATEADD(month, 1, CAST('2008-03-31' AS DATE))",
"trino": "SELECT DATE_ADD('month', 1, CAST(CAST('2008-03-31' AS TIMESTAMP) AS DATE))",
},
)
@@ -88,11 +89,6 @@ class TestRedshift(Validator):
"snowflake": "SELECT DATE_PART(month, CAST('20220502' AS DATE))",
},
)
- self.validate_all("SELECT INTERVAL '5 days'", read={"": "SELECT INTERVAL '5' days"})
- self.validate_all("CONVERT(INT, x)", write={"redshift": "CAST(x AS INTEGER)"})
- self.validate_all(
- "DATEADD('day', ndays, caldate)", write={"redshift": "DATEADD(day, ndays, caldate)"}
- )
self.validate_all(
'create table "group" ("col" char(10))',
write={
@@ -186,7 +182,7 @@ class TestRedshift(Validator):
self.validate_all(
"DATEDIFF('day', a, b)",
write={
- "redshift": "DATEDIFF(day, a, b)",
+ "redshift": "DATEDIFF(day, CAST(a AS DATE), CAST(b AS DATE))",
"presto": "DATE_DIFF('day', CAST(CAST(a AS TIMESTAMP) AS DATE), CAST(CAST(b AS TIMESTAMP) AS DATE))",
},
)
@@ -198,15 +194,18 @@ class TestRedshift(Validator):
)
def test_identity(self):
+ self.validate_identity("SELECT * FROM #x")
+ self.validate_identity("SELECT INTERVAL '5 day'")
+ self.validate_identity("foo$")
+ self.validate_identity("$foo")
self.validate_identity("CAST('bla' AS SUPER)")
self.validate_identity("CREATE TABLE real1 (realcol REAL)")
self.validate_identity("CAST('foo' AS HLLSKETCH)")
- self.validate_identity("SELECT DATEADD(day, 1, 'today')")
self.validate_identity("'abc' SIMILAR TO '(b|c)%'")
+ self.validate_identity("CREATE TABLE datetable (start_date DATE, end_date DATE)")
self.validate_identity(
"SELECT caldate + INTERVAL '1 second' AS dateplus FROM date WHERE caldate = '12-31-2008'"
)
- self.validate_identity("CREATE TABLE datetable (start_date DATE, end_date DATE)")
self.validate_identity(
"SELECT COUNT(*) FROM event WHERE eventname LIKE '%Ring%' OR eventname LIKE '%Die%'"
)
@@ -225,6 +224,22 @@ class TestRedshift(Validator):
self.validate_identity(
"CREATE TABLE SOUP (SOUP1 VARCHAR(50) NOT NULL ENCODE ZSTD, SOUP2 VARCHAR(70) NULL ENCODE DELTA)"
)
+ self.validate_identity(
+ "SELECT DATEADD(day, 1, 'today')",
+ "SELECT DATEADD(day, 1, CAST('today' AS DATE))",
+ )
+ self.validate_identity(
+ "SELECT DATEADD('day', ndays, caldate)",
+ "SELECT DATEADD(day, ndays, CAST(caldate AS DATE))",
+ )
+ self.validate_identity(
+ "CONVERT(INT, x)",
+ "CAST(x AS INTEGER)",
+ )
+ self.validate_identity(
+ "SELECT DATE_ADD('day', 1, DATE('2023-01-01'))",
+ "SELECT DATEADD(day, 1, CAST(DATE('2023-01-01') AS DATE))",
+ )
def test_values(self):
self.validate_all(