Search code examples
google-cloud-storagegoogle-cloud-spanner

Can I automatically populate `created_at` timestamp to transaction timestamp with Google Spanner?


I am looking through the documentation for Google Cloud Spanner, and it looks like write operations return a timestamp when the row was actually written.

But when reading rows, it doesn't seem possible to re-capture that timestamp (either as a column that can be read or as a column that could be limited and sorted on).

I assume that I could just update the row after it is written to append a new column (created_at), but ideally it would be nice to have that field automatically appended.

Is there any way to access the original transaction timestamp when querying spanner? I also noticed that there was a CURRENT_TIMESTAMP() sql function. Is that equivalent to the transaction timestamp?


Solution

  • You can create commit timestamp columns, and Cloud Spanner writes the timestamp as part of the transaction:

    https://cloud.google.com/spanner/docs/commit-timestamp