'pandas read_sql used for CREATE in Postgres db giving TypeError for SQLite
I am trying to use pandas to create functions and tables in postgres.
When I try this query:
conn = = psycopg2.connect(host='localhost', database='my_data',
port='5566', user='postgres', password='postgres')
create_example = '''
create temporary table example(id int primary key, str text, val integer);
insert into example values
(1, 'a', 1),
(2, 'a', 2),
(3, 'b', 2);
'''
pd.read_sql(create_example,conn)
I get the following error TypeError: 'NoneType' object is not iterable

The connection/read_sql works for simple queries but I get the error when I try to CREATE a function or table. Why am I getting the error and why does the error seem to be in SQLite when the connection is to a postgres database? tia
UPDATE: Per the observation by @AdrianKlaver I imported sqlalchemy as follows.
from sqlalchemy import create_engine
def db_connect():
db_connect_string = "postgresql+psycopg2://{user}:{passwd}@{server}:{port}/{db}" \
.format(user="postgres", passwd="postgres",
server="localhost", db="my_data", port="5566")
return create_engine(db_connect_string)
alchemy_conn = db_connect()
So using this alchemy connection:
pd.read_sql(create_example,alchemy_conn.raw_connection())
>>TypeError: 'NoneType' object is not iterable
If I try to use the cursor function I get the error AttributeError: 'psycopg2.extensions.cursor' object has no attribute 'cursor'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
