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

Precision of TIMESTAMP type is different #73

Open
naoina opened this issue May 24, 2022 · 8 comments · May be fixed by #160
Open

Precision of TIMESTAMP type is different #73

naoina opened this issue May 24, 2022 · 8 comments · May be fixed by #160

Comments

@naoina
Copy link

naoina commented May 24, 2022

On cloud-spanner-emulator, the following SQL will get the error spanner: code = "OutOfRange", desc = "Invalid timestamp: '2022-03-31T23:59:59.999999999Z'"

SELECT TIMESTAMP('2022-03-31T23:59:59.999999999Z');

However, Cloud Spanner does not return any error.

Also the emulator accept nanoseconds level value as TIMESTAMP type, but MAX() and MIN() returns microseconds's one.
For example, if SomethingTable has CreatedAt TIMESTAMP NOT NULL column and value of 2022-03-31T14:59:59.999999999Z was inserted.
The following SQL returns 2022-03-31T14:59:59.999999999Z.

SELECT CreatedAt FROM SomethingTable

However, the following SQL returns 2022-03-31T14:59:59.999999Z.

SELECT MAX(CreatedAt) FROM SomethingTable;
@naphatkrit
Copy link

any updates on this issue? we're also running into this.

@krzyjab
Copy link

krzyjab commented Oct 11, 2022

I'm facing the same issue. Interestingly, this seems to be working correctly in the Spanner Emulator:
SELECT PARSE_TIMESTAMP("%FT%H:%M:%E*S%Ez", "2022-10-11T11:47:07.078142285Z");
and this doesn't:
SELECT TIMESTAMP("2022-10-11T11:47:07.078142285Z");

@ebkn
Copy link

ebkn commented Feb 2, 2023

I'm facing the same issue.
This problem happens on gcr.io/cloud-spanner-emulator/emulator:latest on GitHub Actions ubuntu-22.04 machine.
But it works correctly on gcr.io/cloud-spanner-emulator/emulator:latest on my local machine (m1 MacBook Pro).
Maybe this problem is related to architecture.

@gauravpurohit06
Copy link
Collaborator

We are looking into it and will back soon.

@gauravpurohit06 gauravpurohit06 self-assigned this Apr 18, 2023
@gauravpurohit06 gauravpurohit06 removed their assignment Jul 10, 2023
@ThePersonThat
Copy link

any updates? I faced the same issue

@kberezin-nshl
Copy link

Root cause is in ZetaSQL reference implementation, when calling TIMESTAMP(string) function, they ignore nanosecond precision option which Spanner Emulator sets.

There is a workaround though:

SELECT CAST('2022-03-31T23:59:59.999999999Z' AS TIMESTAMP)

totally works

@kberezin-nshl kberezin-nshl linked a pull request Feb 29, 2024 that will close this issue
@kberezin-nshl
Copy link

I raised a pull request which fixes TIMESTAMP() function: #160

@egonelbre
Copy link

Hit the same issue. Here's a small reproducer:

DROP TABLE IF EXISTS Demo;
CREATE TABLE Demo (
    Id   INT64     NOT NULL,
    Time TIMESTAMP NOT NULL
) PRIMARY KEY (Id);

INSERT INTO Demo (Id, Time) VALUES (1, TIMESTAMP '2024-10-16 04:03:54.939599300-00');

SELECT * FROM Demo WHERE Time = (SELECT MAX(Time) FROM Demo);
-- result is empty

SELECT STRING(MAX(Time)) FROM Demo;
-- result is "2024-10-15 21:03:54.939599-07" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants