Reputation: 141
Google has a series of APIs for interacting with Cloud Spanner. However, in all the examples that insert a record, none of them have a way of returning an Insert ID the way a lot of other database APIs would have.
Is there a way to get the InsertID of a record I just inserted into a Cloud Spanner table?
Upvotes: 2
Views: 1903
Reputation: 1
Spanner does support auto populating or incrementing ID's for the primary key. The auto-populating method uses UUID values and the auto-incrementing uses a bit-reversed sequence. https://cloud.google.com/spanner/docs/primary-key-default-value
Once your table is set to use one of those two possible methods, then you can simply return the value of the primary key after an insert, like the following: INSERT INTO my_tbl (name) VALUES ('something') THEN RETURN id;
Upvotes: 0
Reputation: 21
You can refer to the Spanner Doc:
Note: There is no auto-increment capability in Cloud Spanner.
Upvotes: 1
Reputation: 3512
No, this functionality is not available in Cloud Spanner for one very good reason: Cloud Spanner does not support any kind of automatically generated id's, such as sequences, identity columns or automatically generated UUID's. The primary key value of a row is always specified by the client, which means that there is no need for a function for returning the primary key value to client (as it is already known by the client).
Upvotes: 3