Home > Software engineering >  Python binding variables
Python binding variables

Time:05-19

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?

CodePudding user response:

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})
  • Related