How do I get the last ID/SERIAL value inserted into a table? Is there a CockroachDB function similar to SQL Server’s SCOPE_IDENTITY()?
There’s no function in CockroachDB for returning last inserted values. But you can use the RETURNING clause of the INSERT statement.
For example, this is how you’d use RETURNING to return an auto-generated SERIAL value:
CREATE TABLE users (id SERIAL, name STRING);
INSERT INTO users (name) VALUES ('mike') RETURNING id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With