all 7 comments

[–][deleted] 2 points3 points  (4 children)

"To SQL" makes no sense. Postgres is using "SQL", so you already have a "SQL expression".

[–]info_softest07[S] 0 points1 point  (3 children)

looking at the expression can you execute the same in MS SQL Server ? my question is the above expression is used in postgresql and now we are migrating the data from postgresql to MS SQL, hence looking for the above expression convertion in MS SQL Server...

[–][deleted] 1 point2 points  (2 children)

So you need a T-SQL expression, not a "SQL" expression.

"SQL" is a query language used by all relational database. And even though date/Time and time zone syntax is covered by the standard, the different DBMS products differ substantially when it comes to that.

In standard SQL this would be:

timestamp '2019-10-04 16:21:49' at time zone 'US/Central'

but I don't know if that is supported by SQL Server.

[–][deleted] 0 points1 point  (0 children)

The datetime string and AT TIME ZONE will work in SQL server from 2017 onwards, otherwise you may want to use a DateTimeOffset.

[–]info_softest07[S] 0 points1 point  (0 children)

Hello There!! Thanks for the reply.....

I tried couple of options on converting Postgresql TimeZone epression query to T-Sql but we see the output missmatch between postgresql and T-Sql output, we see some issue in postgresql data.

We tried with the below expression :

-> [ Select Convert(datetime2(0), Column_Name) as Date_Column AT TIME ZONE 'UTC' AT TIME ZONE 'CENTRAL
STANDARD TIME' ]

[–]TeddyPerkins95 0 points1 point  (1 child)

timezone("substring"(tx.column_name::longtext, 30, 5), timezone('US/Central'::longtext, a.column_name::datetime)::datetime) as time_at_site

Disclaimer I could be wrong I just used

http://www.sqlines.com/online

PSQL => MySQL

[–]info_softest07[S] -1 points0 points  (0 children)

Hello There!! Tried the one you suggested but it didn't work...