summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_tsql.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dialects/test_tsql.py')
-rw-r--r--tests/dialects/test_tsql.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index 953d64d..ca6d70c 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -17,17 +17,29 @@ class TestTSQL(Validator):
self.validate_identity("PRINT @TestVariable")
self.validate_identity("SELECT Employee_ID, Department_ID FROM @MyTableVar")
self.validate_identity("INSERT INTO @TestTable VALUES (1, 'Value1', 12, 20)")
- self.validate_identity(
- "SELECT x FROM @MyTableVar AS m JOIN Employee ON m.EmployeeID = Employee.EmployeeID"
- )
self.validate_identity('SELECT "x"."y" FROM foo')
self.validate_identity("SELECT * FROM #foo")
self.validate_identity("SELECT * FROM ##foo")
self.validate_identity(
+ "SELECT x FROM @MyTableVar AS m JOIN Employee ON m.EmployeeID = Employee.EmployeeID"
+ )
+ self.validate_identity(
"SELECT DISTINCT DepartmentName, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY BaseRate) OVER (PARTITION BY DepartmentName) AS MedianCont FROM dbo.DimEmployee"
)
self.validate_all(
+ "SELECT DATEPART(year, TRY_CAST('2017-01-01' AS DATE))",
+ read={"postgres": "SELECT DATE_PART('year', '2017-01-01'::DATE)"},
+ )
+ self.validate_all(
+ "SELECT DATEPART(month, TRY_CAST('2017-03-01' AS DATE))",
+ read={"postgres": "SELECT DATE_PART('month', '2017-03-01'::DATE)"},
+ )
+ self.validate_all(
+ "SELECT DATEPART(day, TRY_CAST('2017-01-02' AS DATE))",
+ read={"postgres": "SELECT DATE_PART('day', '2017-01-02'::DATE)"},
+ )
+ self.validate_all(
"SELECT CAST([a].[b] AS SMALLINT) FROM foo",
write={
"tsql": 'SELECT CAST("a"."b" AS SMALLINT) FROM foo',
@@ -281,19 +293,20 @@ WHERE
def test_datename(self):
self.validate_all(
- "SELECT DATENAME(mm,'01-01-1970')",
- write={"spark": "SELECT DATE_FORMAT('01-01-1970', 'MMMM')"},
+ "SELECT DATENAME(mm,'1970-01-01')",
+ write={"spark": "SELECT DATE_FORMAT(CAST('1970-01-01' AS TIMESTAMP), 'MMMM')"},
)
self.validate_all(
- "SELECT DATENAME(dw,'01-01-1970')",
- write={"spark": "SELECT DATE_FORMAT('01-01-1970', 'EEEE')"},
+ "SELECT DATENAME(dw,'1970-01-01')",
+ write={"spark": "SELECT DATE_FORMAT(CAST('1970-01-01' AS TIMESTAMP), 'EEEE')"},
)
def test_datepart(self):
self.validate_all(
- "SELECT DATEPART(month,'01-01-1970')",
- write={"spark": "SELECT DATE_FORMAT('01-01-1970', 'MM')"},
+ "SELECT DATEPART(month,'1970-01-01')",
+ write={"spark": "SELECT DATE_FORMAT(CAST('1970-01-01' AS TIMESTAMP), 'MM')"},
)
+ self.validate_identity("DATEPART(YEAR, x)", "FORMAT(CAST(x AS DATETIME2), 'yyyy')")
def test_convert_date_format(self):
self.validate_all(