Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python binding variables

I am completely lost here:

v_sql = "SELECT widget_name, widget_url FROM widget_calls WHERE widget_name = :widget"
cursor.execute(v_sql, widget=widget_name)
df_wid = pd.read_sql(v_sql, con=connection)

Result:

pandas.io.sql.DatabaseError: Execution failed on sql 'SELECT widget_name, widget_url FROM widget_calls WHERE widget_name = :widget': ORA-01008: not all variables bound

There is 1 bind variable, :widget, and 1 declaration in the execute. So, what am I missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The cursor.execute call and the pd.read_sql call are completely unrelated. You’re doing the query twice, and throwing away the first result. I would delete the useless cursor.execute.

And for read_sql, you need:

df_wid = pd.read_sql( v_sql, con=connection, params={'widget': widget_name})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading