Databricks SDK for Python: Errors with parameters for Statement Execution

Phuonganh
Databricks Partner

Hi team,

Im using Databricks SDK for python to run SQL queries. I created a variable as below:

param = [{'name' : 'a', 'value' :x'}, {'name' : 'b', 'value' : 'y'}]

and passed it the statement as below

_ = w.statement_execution.execute_statement( warehouse_id = "123", catalog = "aaa", statement = "SELECT * FROM table_a WHERE name = :a and age = :b", parameters = param)

and I get an attribute error: 'dict' object has no attribute 'as_dict'

But this is exactly how databricks instructed on their website. Thank you for your help

 

DonkeyKong
New Contributor II

@Retired_mod This does not help resolve the issue. I am experiencing the same issue when following the above pointers. Here is the statement:

response = w.statement_execution.execute_statement(
    statement='ALTER TABLE users ALTER COLUMN :col_name SET NOT NULL', 
    warehouse_id='<warehouseID>',
    parameters=[{'name': 'col_name', 'value': 'user', 'type': 'STRING'}]
)

This results in the same AttributeError outlined by @Phuonganh above.

jessica3
New Contributor II

Has anyone found the solution to this? I am running into the same error

vfrcode
New Contributor II
The following works:

 

response = w.statement_execution.execute_statement(
    statement='ALTER TABLE users ALTER COLUMN :col_name SET NOT NULL', 
    warehouse_id='<warehouseID>',
    parameters=[sql.StatementParameterListItem(name='col_name' value='user', type='STRING')]
)