Upsert: insert or update

Insert a row, or update it when the unique key already exists.

sql intermediate #postgres#upsert#writes
Abrir no playground
sql-upsert-on-conflict.sql
INSERT INTO page_views (path, day, views)
VALUES ('/pricing', CURRENT_DATE, 1)
ON CONFLICT (path, day)
DO UPDATE SET views = page_views.views + EXCLUDED.views;