Fixed 'current transaction is aborted' error when using PostgreSQL