Skip to content
Advertisement

How to create sql db2 data table using python?

I would like to run an sql db2 query on python that will create a data table in a public schema but I’m stuck because of this error

ResourceClosedError: This result object does not return rows. It has been closed automatically.

Below is the Python code I’m using, I have deleted the private information.

Please help in fixing my code and thanks in advance.

Advertisement

Answer

Error indicates Pandas read_sql cannot import data into a data frame since you only have DDL actions: DROP TABLE and CREATE TABLE and nothing that return rows like SELECT.

If not using Pandas for data analytics, simply run your queries with SQL Alchemy transactions. And no need to close using context manager like with:

Or combined:

And if you really do need a data frame, use engine object in read_sql after transactions:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement