package db import ( "errors" "github.com/jackc/pgerrcode" "github.com/jackc/pgx/v5/pgconn" ) // IsUniqueViolation reports whether err is Postgres refusing a row because // another row already holds the same unique value: a username or email // that is taken, or a second album row claiming one MBID. Callers use it to // tell "that already exists" apart from a write that failed. func IsUniqueViolation(err error) bool { var pgErr *pgconn.PgError return errors.As(err, &pgErr) && pgErr.Code == pgerrcode.UniqueViolation }