GoogleCloudPlatform / cloud-spanner-emulator

An open source emulator for Cloud Spanner.
Apache License 2.0
265 stars 44 forks source link

PENDING_COMMIT_TIMESTAMP() in SELECT supported in emulator, unsupported in Cloud Spanner #68

Closed jzelinskie closed 1 year ago

jzelinskie commented 2 years ago

We're creating rows in one table and copying them in to another table for auditing within the same transaction. We initially tried to copy using a subquery along the lines of INSERT ... FROM (SELECT PENDING_COMMIT_TIMESTAMP(), columns... FROM table).

Cloud Spanner does not support PENDING_COMMIT_TIMESTAMP() in a SELECT statement, but the emulator did not throw any errors when provided a query as described above. It was only once we ran against a live Cloud Spanner instance that we discovered this type of query was unsupported.

jameslintaylor commented 1 year ago

My team is running into a similar issue. Specifically that PENDING_COMMIT_TIMESTAMP is allowed by the emulator in a COALESCE, in odds with:

The PENDING_COMMIT_TIMESTAMP function may only be used as a value for INSERT or UPDATE of an appropriately typed column. It cannot be used in SELECT, or as the input to any other scalar expression.

From https://cloud.google.com/spanner/docs/reference/standard-sql/timestamp_functions

xinjiacs commented 1 year ago

V15.5 is out, we believe that issue has been resolved, and emulator should have the same behavior with cloud spanner. Thanks for reporting this issue.

gauravpurohit06 commented 1 year ago

Thank you @jzelinskie for reporting the issue. Closing it.