sql
sql copied to clipboard
Insert returning values?
I'd like to create a row in a table with an auto-incrementing primary key, retrieve the generated key, and read the value later. Some SQL variants allow specifying that an INSERT statement should return values, e.g. Postgres has the INSERT ... RETURNING clause, Sqlite has the last_insert_rowid() function, SQL Server has INSERT ... OUTPUT, etc. Would a #:returning keyword listing column names make sense for the insert syntax?
I would like to support (some) extensions like PostgreSQL's RETURNING clause, but I haven't decided how to do that yet. And I don't want to try to unify extentions that are too different. For example, it seems like it might be reasonable to unify PostgreSQL's RETURNING and SQL Server's OUTPUT, but it would not make sense to try to unify those with Sqlite's last_insert_rowid().