Laurent Hinoul

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - John F. Woods

How to fix postgres error: current transaction is aborted, commands ignored until end of transaction block

In this post, I will tell you how to fix the error that PostgreSQL throws when you try to execute an SQL-statement.

When you execute a non-correct SQL statement, you correct it and try to execute it again, you can have an error like: ERROR: current transaction is aborted, commands ignored until end of transaction block

By executing that wrong SQL-statement, postgreSQL will not terminate the execution by itself so you need to rollback manually. You can do this by simply execute the following statement:

Example

I want to execute the non-correct SQL-statement:

PostgreSQL will throw the following error: syntax error at or near ‘fro’. This means my word ‘from’ is not correctly typed. So I now want to execute the correct statement:

Here, PostgreSQL will throw the following error: current transaction is aborted, commands ignored until end of transaction block. This is because the wrong SQL-statement is still trying to commit. Now, to rollback, type the following SQL-statement:

Now we can try to execute the correct SQL-statement again. You will notice that it works this time. Enjoy 😀

1 comment for “How to fix postgres error: current transaction is aborted, commands ignored until end of transaction block

  1. Bam Shankar Kumar
    22/03/2017 at 06:02

    Awesome!!! It really helped me!!

Leave a Reply

%d bloggers like this: