Search code examples
unix-timestampgoogle-cloud-spanner

How are timestamps internally represented in Google Spanner?


I can't seem to find any information on how Spanner stores timestamps (columns) internally - the documentation only mentions:

Note that this is not the internal representation of the timestamp; it is only a human-understandable way to describe the point in time that the timestamp represents.

Are they stored internally as Unix timestamps (integers)? And if so, how does spanner store any timezone information?


Solution

  • Cloud Spanner does not store the timezone that was used when inserting a value into a TIMESTAMP column. It only stores the point in time. It is up to the client to choose which timezone should be used to format a TIMESTAMP value that is read from the database.

    So if you execute the following:

    insert into my_table (id, col_timestamp) 
    values (1, timestamp '2022-10-01T10:00:00+01:00');
    
    select *
    from my_table;
    

    The timezone that is used to render the data that is returned by the select statement is chosen by the client. The actual underlying timestamp string that is returned by Cloud Spanner is always in Zulu time.

    See also https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#timestamp_type