Fixing PostgreSQL Upsert That Overwrites Unchanged Rows and Breaks updated_at
Your INSERT ... ON CONFLICT DO UPDATE is firing on every row, stamping updated_at even when nothing changed. Here's why that happens and exactly how to fix it with a conditional DO UPDATE clause.