[Tutor] pandas read sql query advice

Glenn Schultz glennmschultz at me.com
Fri Apr 27 16:52:22 EDT 2018


All,

I have the following set-up (below) which will be used to call data from multiple sectors.  There is a sql query (transact sql) and connection.  This works fine.  However, I would like to parametrize the query so I can enter different sectors.  I have checked through pyodbc and several SO posts.  However, I am stuck and cannot get the parametrized version to work.  Most examples I have found are either sqlite or postgres.

sql ="""select foo from mutable where model sector = 'mysector'"""
conn = myconn

def modeldata(modelquery, conn)
modeldata = pandas.read_sql_query(sql, conn)
return modeldata

Here is what I have tried (various combinations) - what am I doing wrong?

sql ="""select foo from mutable where model sector = ?""", [params]
conn = myconn

def modeldata(modelquery, conn, params)
modeldata = pandas.read_sql_query(sql, conn, params)
return modeldata

Thanks in advance,
Glenn


More information about the Tutor mailing list