Skip to content

Is there a way to "Get or Insert" in a single query_row call? #1349

Answered by gwenn
Byron asked this question in Questions
Discussion options

You must be logged in to vote

See https://sqlite.org/lang_upsert.html (if there is an unique constraint on version).
And https://sqlite.org/lang_returning.html

sqlite> CREATE TABLE gitoxide_version(version INTEGER NOT NULL UNIQUE);
sqlite> INSERT INTO gitoxide_version (version) VALUES (1) ON CONFLICT DO NOTHING RETURNING rowid;
1
sqlite> INSERT INTO gitoxide_version (version) VALUES (1) ON CONFLICT DO NOTHING RETURNING rowid;
sqlite> -- we should do a fake update instead:
sqlite> INSERT INTO gitoxide_version (version) VALUES (1) ON CONFLICT DO UPDATE SET version = version RETURNING rowid;
1
sqlite> INSERT INTO gitoxide_version (version) VALUES (3) ON CONFLICT DO UPDATE SET version = version RETURNING rowid;
2
sqlite> I…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Byron
Comment options

@gwenn
Comment options

@Byron
Comment options

Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants