Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timezone(timestamp(p) with time zone) -> varchar extraction function to get IANA timezone ID #20893

Open
stephen-zhao opened this issue Mar 1, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@stephen-zhao
Copy link

Request

Similar to the current_timezone() function which returns the timezone of the current session, it would be nice to generalize this to allow extraction of timezone info from any provided timestamp(p) with time zone. Currently there are already functions to get timezone offsets (extract(TIMEZONE_HOUR from x) and extract(TIMEZONE_MINUTE from x)), but this loses information about the actual timezone. A lossless extraction function that would return the IANA timezone ID would be ideal.

Workaround

You can cast the timestamp(p) with time zone to a string, and manually extract the suffix.

@hashhar
Copy link
Member

hashhar commented Mar 1, 2024

cc: @martint

@ebyhr
Copy link
Member

ebyhr commented Mar 5, 2024

The argument for EXTRACT is defined in SQL standard:

<time zone field> ::=
    TIMEZONE_HOUR
  | TIMEZONE_MINUTE

Is format_datetime function sufficient in your use case?

SELECT format_datetime(TIMESTAMP '2001-01-09 13:04:05.321 Asia/Tokyo', 'ZZZ');
   _col0
------------
 Asia/Tokyo

@martint
Copy link
Member

martint commented Jun 21, 2024

Apologies for the delay. This is a reasonable request. To keep alignment with existing extraction functions (https://trino.io/docs/current/functions/datetime.html#convenience-extraction-functions), we should define it as:

timezone(<timestamp(p) with time zone>) -> varchar
timezone(<time(p) with time zone>) -> varchar

@martint martint added enhancement New feature or request good first issue Good for newcomers and removed syntax-needs-review labels Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

No branches or pull requests

4 participants