diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-07-06 07:28:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-07-06 07:28:12 +0000 |
commit | 374a0f6318bcf423b1b784d30b25a8327c65cb24 (patch) | |
tree | 9303a1cbdba85b5d9781ebef32eb1902d3790c99 /tests/dialects/test_tsql.py | |
parent | Releasing debian version 16.7.7-1. (diff) | |
download | sqlglot-374a0f6318bcf423b1b784d30b25a8327c65cb24.tar.xz sqlglot-374a0f6318bcf423b1b784d30b25a8327c65cb24.zip |
Merging upstream version 17.2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/dialects/test_tsql.py | 31 |
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( |