I'm assuming you've already committed the transaction, but just in case you haven't, you can simply do:
ROLLBACK TRANSACTION;
Since I'm assuming you've tried that, the unfortunate answer is that your only option is a database restore from the last known good state.
There are some options and plugins that might help avoid this problem in the future, but they all come with performance costs. See these other Stack Overflow questions for some information Database Content Versioning and Postgres reverting back.