Postgres upsert with ON CONFLICT
SQLPublic
-- Insert a row, or update it if the unique key already exists
INSERT INTO settings (user_id, key, value)
VALUES ($1, $2, $3)
ON CONFLICT (user_id, key)
DO UPDATE SET value = EXCLUDED.value, updated_at = now()
RETURNING *;Comments(0)
No comments yet. Start the conversation.