Use transaction for postgres cursor only if connection is not in transaction mode