1
votes

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

1 Answers

3
votes

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.