QuickSnip

Tag: database

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

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;
Updated Jul 17, 2026

SQL query to find rows with duplicate values in a column.

SELECT email, COUNT(*) AS occurrences
FROM users
GROUP BY email
HAVING COUNT(*) > 1
ORDER BY occurrences DESC;
Updated Jul 17, 2026