Using WorkspaceClient -- run a saved query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 12:34 PM
I've saved a query on my sql warehouse which has a parameter called :list_parameter.
I've found my query id as follows:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
for query in w.queries.list():
print(f"query: {query.display_name}, paramaters: {query.parameters}")
What i now can't seem to find out is how to run and wait for the query response on my client.
Something like w.queries.run(id = "xyz", parameters = {'list_parameter": "my, excellent, list"})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 04:40 PM
Hi @lprevost
The WorkspaceClient provides APIs to manage Query objects. But it doesn't provide the API to run it. If you need to run the query from a notebook, you can pass the query text into `spark.sql`. It returns SparkDataFrame. I hope this helps!
query = w.queries.get("query-uuid")
df = spark.sql(query.query_text, {"param_name": "param_value"})
display(df)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 10:49 AM
Was hoping to run a remote query from a WorkspaceClient and get a result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 01:10 AM
Thanks for describing the detail. Now I understand your motivation better.
In that case, the execute_statement API can be used. Please take a look and let me know if it suits your need.

