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

H

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:

rollback;

Example

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

select * from account

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:

select * from account

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:

rollback;

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

3 comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories