← Back to browse
PostgreSQL upsert (ON CONFLICT)
Insert a row, or update it if the unique key already exists.
SQL5 linesUpdated Jul 17, 2026
SQL
INSERT INTO users (email, name, updated_at)
VALUES ($1, $2, NOW())
ON CONFLICT (email)
DO UPDATE SET name = EXCLUDED.name, updated_at = NOW()
RETURNING id;