I have a Timestamp_NTZ column where I know the data are in Central (America/Chicago) timezone. How do I convert it into Timestamp_TZ format during select.
I couldn't just convert to varchar and add timezone offset and back to timestamp_tz because of different offset during daylight saving.
I found following two approaches but they involves more code/typing. Looking for elegant solution.
Alter session to the required timezone and use TO_TIMESTAMP_TZ() function. The drawback of this approach is that its two separate query and it cannot be used in stored procedure with run as Owner.
alter session set timezone = 'America/Chicago';
select TO_TIMESTAMP_TZ(column_name) from table_name;
Use TIMESTAMP_TZ_FROM_PARTS function. This involves more typing and looks complicated.
select TIMESTAMP_TZ_FROM_PARTS(Year(column_name), Month(column_name), Day(column_name), Hour(column_name), Minute(column_name), Second(column_name), 0, 'America/Chicago') from table_name;
Is there a simple way to do this in snowflake, something like:
select TO_TIMESTAMP_TZ(column_name, 'America/Chicago') from table_name;
question from:
https://stackoverflow.com/questions/65895131/easiest-way-to-convert-timestamp-ntz-to-timestamp-tz-in-snowflake-database 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…