SQLite Forum

Shortcut to change a non changing update or upsert in a noop
Login
Hello

I try to avoid updates or upsert which are not changing values. So I write
very often (quite long) WHERE clauses. Is there maybe a more elegant way like a pragma to always check writes to avoid this code?


here a simple example:

INSERT INTO types(importId, name,  accessSemantics, sourceId)
VALUES(?1, ?2, ?3, nullif(?4, -1)) 
ON CONFLICT DO UPDATE SET prototypeId=excluded.prototypeId, accessSemantics=excluded.accessSemantics, sourceId=excluded.sourceId 
WHERE prototypeId IS NOT excluded.prototypeId OR accessSemantics IS NOT excluded.accessSemantics OR sourceId IS NOT excluded.sourceId 
RETURNING typeId

Thank you, Marco