@contextmanager<EOL>def ignore_unique_violation():
try:<EOL><INDENT>yield<EOL><DEDENT>except IntegrityError as error:<EOL><INDENT>if not is_unique_violation(error):<EOL><INDENT>raise<EOL><DEDENT><DEDENT>
Context manager for gobbling unique violations.

NOTE: If a unique violation is raised, the existing psql connection will
not accept new commands.  This just silences the python-level error.  If
you need emit another command after possibly ignoring a unique violation,
you should explicitly use savepoints.