devanbenz commented on issue #12218: URL: https://github.com/apache/datafusion/issues/12218#issuecomment-2350193497
> > Datafusion needs to implement something similar to the following in Clickhouse for casting to timestamp with a specified timezone: > > I think you can do it like > > ```sql > select now() AT TIME ZONE 'America/Denver'; > ``` > > Though it would be awesome if that was documented (it doesn't appear to be in the SQL reference): [datafusion.apache.org/search.html?q=AT+TIMEZONE](https://datafusion.apache.org/search.html?q=AT+TIMEZONE) Taking a look at this it appears that casting to a timezone does work in datafusion *but* it doesn't function to how I would expect (or maybe it needs to be a different type of cast similar to clickhouse syntax?): Clickhouse: ``` :) SELECT toTimeZone(now(), 'America/Denver')::timestamp; SELECT CAST(toTimeZone(now(), 'America/Denver'), 'timestamp') Query id: 2f766f9f-9723-41dc-9a01-901421793e65 ┌─CAST(toTimeZone(now(), 'America/Denver'), 'timestamp')─┐ 1. │ 2024-09-13 16:00:10 │ └────────────────────────────────────────────────────────┘ 1 row in set. Elapsed: 0.002 sec. :) SELECT toTimeZone(now(), 'America/Denver')::timestamp('America/Denver'); SELECT CAST(toTimeZone(now(), 'America/Denver'), 'timestamp(\'America/Denver\')') Query id: db0d0937-89b8-4ea4-93cd-d07c157733b2 ┌─CAST(toTimeZone(now(), 'America/Denver'), 'timestamp(\'America/Denver\')')─┐ 1. │ 2024-09-13 15:00:21 │ └────────────────────────────────────────────────────────────────────────────┘ 1 row in set. Elapsed: 0.002 sec. ``` Datafusion: ``` > select (now() at time zone 'America/Chicago'); +----------------------------------+ | now() | +----------------------------------+ | 2024-09-13T15:45:08.013132-05:00 | +----------------------------------+ 1 row(s) fetched. Elapsed 0.007 seconds. > select (now() at time zone 'America/Chicago')::timestamp; +----------------------------+ | now() | +----------------------------+ | 2024-09-13T20:45:16.085603 | +----------------------------+ 1 row(s) fetched. Elapsed 0.007 seconds. > select (now() at time zone 'America/Chicago')::timestamp at time zone 'America/Chicago'; +----------------------------------+ | now() | +----------------------------------+ | 2024-09-13T20:45:28.485804-05:00 | +----------------------------------+ 1 row(s) fetched. Elapsed 0.008 seconds. ``` Thats more so what I mean -- that when casting to a timestamp with a given timezone the output should abide by the timezone where it appears that `AT TIME ZONE` casts from a `timestamp` to a `timestamptz` (in postgres terminology). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
