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

sql: Add support for convert_tz() and equivalent functions #27023

Closed
tim-o opened this issue Jun 27, 2018 · 8 comments
Closed

sql: Add support for convert_tz() and equivalent functions #27023

tim-o opened this issue Jun 27, 2018 · 8 comments
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) no-issue-activity O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs S-3-productivity Severe issues that impede the productivity of CockroachDB developers.

Comments

@tim-o
Copy link
Contributor

tim-o commented Jun 27, 2018

FEATURE REQUEST

  1. Does an issue already exist addressing this request? If yes, please add a 👍 reaction to the existing issue. If not, move on to step 2.

Dependent on but not identical to #26097 .

  1. Please describe the feature you are requesting, as well as your proposed use case for this feature.

Add support for a convert_tz() function as described in https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz , or equivalent.

  1. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have). Are you currently using any workarounds to address this issue?

Switchfour to comment below.

@tim-o tim-o added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs S-3-productivity Severe issues that impede the productivity of CockroachDB developers. labels Jun 27, 2018
@thebitmechanic
Copy link

We have data that when queried is specific to a particular timezone. The data includes a UTC timestamp that represents the point in time that the data takes place. For example flight segments.

We need to be able to query all segments that occurred on a specific day considering what the day is the timezone. The following example is from MariaDB.

select * from segments_air where date_format(convert_tz(date_add(from_unixtime(0), interval start_tstamp second), '+00:00', start_timezone), '%e %b %Y')='19 Feb 2018';
Side note, in our application we have indexed values in the where clause, and the function in this example would filter the indexed records.

This is an important issue to us because we would need to query all records, then in our code apply the timezone then exclude the records that don't apply. Obviously we could work around it, but we would prefer that the database handle it.

@knz
Copy link
Contributor

knz commented Jun 30, 2018

@thebitmechanic why not convert the desired date to UTC instead in the comparison? e.g. select * from segments_air where start_tstamp::date = ('2018-02-19'::interval + start_timezone)::date?

@knz
Copy link
Contributor

knz commented Jun 30, 2018

(then to make this query fast you'd need to convert the test x::date = y::date to something like x >= ts_date1 and x < ts_date2 where ts_date2 is precomputed to be ts_date1 + 1 day.)

@thebitmechanic
Copy link

@knz start_timezone is an IANA timezone not an offset. Are you suggesting converting the following to a unix timestamp outside of the query?

'2018-02-19'::interval + start_timezone

I haven't seen anywhere in the cockroach docs that describes using IANA timezones.

@knz
Copy link
Contributor

knz commented Oct 9, 2018

All the timezone names map to an offset expressed in seconds. Are you requesting a function that computes that amount of seconds as an INTERVAL value, so you can use it to compute what you need?

@thebitmechanic
Copy link

Our database stores all timestamps as unix timestamps. The example above is looking for all air segments that occur on a day, 19 Feb 2018 for example. start_tstamp is essentially a departure date and time in seconds. We need to be able to apply the IANA timezone (start_timezone) to the start_tstamp to determine if the segment occurs on 19 Feb 2018. Without doing this the start_tstamp is a unix timestamp which of course is UTC. We could select a number of records, iterate over them while programmatically applying the IANA timezone looking for segments that occur on 19 Feb 2018, but it would be nice if the database could just handle it.

@github-actions
Copy link

github-actions bot commented Jun 6, 2021

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
5 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@knz
Copy link
Contributor

knz commented Jun 7, 2021

crdb now supports the AT TIME ZONE operator

@knz knz closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) no-issue-activity O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs S-3-productivity Severe issues that impede the productivity of CockroachDB developers.
Projects
None yet
Development

No branches or pull requests

3 participants