1

I did this in my python code, based on the documentation here and it's mention here

# anything can be used as a file if it has .read() and .readline() methods
data = StringIO.StringIO()
data.write('\n'.join(['Tom\tJenkins\t37',
                  'Madonna\t\N\t45',
                  'Federico\tDi Gregorio\t\N']))
data.seek(0)

curs.copy_from(data, 'distributors')

I got this error: Traceback (most recent call last): File "", line 1, in cursor.copy_from(data, 'distributors') InternalError: current transaction is aborted, commands ignored until end of transaction block

1 Answer 1

3

Found the answer here:

There was an attempted query run of an erroneous query using the same database connection. (For details: I had run a copy_from execution on this db connection with incorrect data. It had failed. And, then I modified my data to be in correct format)

When your previous query/command on the database using this connection had a problem/error, it needs to be rolled back using connection.rollback() call. Once, you execute that code, and re-run the fresh correct code, you would get data to be properly copied from Python code to Postgres database.

Sign up to request clarification or add additional context in comments.

1 Comment

I did a con.commit() after each statement and worked like a charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.