Search code examples
pythonoraclevariablesbind

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?


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