I have a query which upserts into Postgres when a key conflicts only if there are changes to one of the other columns (to avoid unnecessary inserts and returned rows where nothing was actually changed):
INSERT INTO public.test_upsert (some_id, a, b, note) VALUES ('c', 1, true, 'asdf') ON CONFLICT (some_id) DO UPDATE SET a = excluded.a, b = excluded.b, note = excluded.note WHERE test_upsert.a IS DISTINCT FROM excluded.a OR test_upsert.b IS DISTINCT FROM excluded.b OR test_upsert.note IS DISTINCT FROM excluded.note RETURNING *;
My question is: is there shorthand for this? I basically want to either insert a new record update the rows when any of the columns being inserted are distinct from the existing columns. Writing out each column individually gets quite verbose, although it is more explicit.