Agreed. Would be good. On Fri, Jun 8, 2018 at 1:25 PM, Rowan Worth <row...@dug.com> wrote:
> On 3 June 2018 at 07:28, Scott Robison <sc...@casaderobison.com> wrote: > > > I've encountered a feature that I think would be awesome: > > https://www.postgresql.org/docs/9.3/static/dml-returning.html > > > > Example: INSERT INTO blah (this, that, another) VALUES (x, y, z) > RETURNING > > id; > > > > > > my thoughts are just that this could greatly simplify a lot of sql > > code that currently has to prepare and execute at least two statements > > to accomplish what is conceptually an atomic task. > > > > For most use cases you only need a single query: > > if (sqlite3_exec(db, "INSERT INTO blah (this, that, another) VALUES (x, > y, z)") == SQLITE_OK) { > long id = sqlite3_last_insert_rowid(db); > ... > } > > Of course this relies on the table's primary key being a rowid alias, where > the RETURNING syntax is presumably flexible enough to support multi-column > keys and such. Although I'm not sure how you'd generate sane defaults for > such columns... > > -Rowan > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users