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

builtins: implement to_timestamp #77591

Closed
andyli opened this issue Mar 10, 2022 · 6 comments · Fixed by #82523
Closed

builtins: implement to_timestamp #77591

andyli opened this issue Mar 10, 2022 · 6 comments · Fixed by #82523
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. good first issue O-community Originated from the community

Comments

@andyli
Copy link

andyli commented Mar 10, 2022

Describe the problem

To use a timestamp value in decimal, in Postgres, I use the to_timestamp() function as follows

select to_timestamp(1646906263.278);

Since cockroach doesn't have to_timestamp(), I use a cast instead:

select 1646906263.278::timestamptz;

But it results in SQL Error [42846]: ERROR: invalid cast: decimal -> timestamptz

Casting an integer to timestamptz works, thought it loses precision:

select 1646906263::timestamptz; # removed .278

Environment:

  • CockroachDB CCL v21.2.6 (x86_64-unknown-linux-gnu, built 2022/02/22 18:30:37, go1.16.6)

Instructions for contributors:

Add a built-in in https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/sem/builtins/builtins.go
Add a test in https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/logictest/testdata/logic_test/timestamp, and run make testbaselogic FILES='timestamp' TESTFLAGS='-rewrite' to test it.
Run make buildshort to regenerate automatically generated files.
Submit a PR.


Jira issue: CRDB-13671
Epic CRDB-14049

@andyli andyli added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Mar 10, 2022
@blathers-crl
Copy link

blathers-crl bot commented Mar 10, 2022

Hello, I am Blathers. I am here to help you get the issue triaged.

Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here.

I was unable to automatically find someone to ping.

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-untriaged blathers was unable to find an owner labels Mar 10, 2022
@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Mar 14, 2022
@yuzefovich yuzefovich removed X-blathers-untriaged blathers was unable to find an owner T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Mar 14, 2022
@otan otan changed the title Unable to cast decimal -> timestamptz builtins: implement to_timestamp Mar 15, 2022
@otan
Copy link
Contributor

otan commented Mar 15, 2022

thanks! i think our preference here is to implement to_timestamp, so changed accordingly.

@deepto98
Copy link

Hi, can I pick this up?

@rafiss
Copy link
Collaborator

rafiss commented Mar 27, 2022

@deepto98 sure, it's best if you go ahead and submit a PR as per the instructions in the issue, and following our contribution guidelines

craig bot pushed a commit that referenced this issue Jun 9, 2022
82523: builtins: implement to_timestamp for Unix epoch r=otan a=nnaka2992

fixes #77591

Previously, CockroachDB did not support to_timestamp(double precision)
In PostgreSQL, the function also handles INT, DECIMAL and text by casting,
so the commit also implements those for compatibility.

Release note (sql change): Add new function to_timestamp which
converts Unix epoch of FLOAT, INT, DECIMAL and text to Timestamp with time zone.

Co-authored-by: nnaka2992 <nnaka2992@gmail.com>
@craig craig bot closed this as completed in a7b632a Jun 9, 2022
@simplenotezy
Copy link

Just curious, when will this be released?

@rafiss
Copy link
Collaborator

rafiss commented Nov 8, 2022

@simplenotezy This will be a part of the v22.2 release. There are beta versions available for you to test with: https://www.cockroachlabs.com/docs/releases/v22.2.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. good first issue O-community Originated from the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants