Skip to main content

queries

Creates, updates, deletes, gets or lists a queries resource.

Overview

Namequeries
TypeResource
Iddatabricks_workspace.sql.queries

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringUUID identifying the query.
warehouse_idstringID of the SQL warehouse attached to the query.
display_namestringDisplay name of the query that appears in list views, widget headings, and on the query page.
last_modifier_user_namestringUsername of the user who last saved changes to this query.
owner_user_namestringUsername of the user that owns the query.
apply_auto_limitboolean
catalogstringName of the catalog where this query will be executed.
create_timestringTimestamp when this query was created.
descriptionstringGeneral description that conveys additional information about this query such as usage notes.
lifecycle_statestringIndicates whether the query is trashed. (ACTIVE, TRASHED)
parametersarrayList of query parameter definitions.
parent_pathstringWorkspace path of the workspace folder containing the object.
query_textstringText of the query to be run.
run_as_modestringSets the "Run as" role for the object. (OWNER, VIEWER)
schemastringName of the schema where this query will be executed.
tagsarray
update_timestringTimestamp when this query was last updated.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectid, deployment_nameGets a query.
listselectdeployment_namepage_size, page_tokenGets a list of queries accessible to the user, ordered by creation time. Warning: Calling this API
createinsertdeployment_nameCreates a query.
updateupdateid, deployment_name, update_maskUpdates a query.
deletedeleteid, deployment_nameMoves a query to the trash. Trashed queries immediately disappear from searches and list views, and

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
deployment_namestringThe Databricks Workspace Deployment Name (default: dbc-abcd0123-a1bc)
idstringstr
page_sizeinteger:param page_token: str (optional)
page_tokenstring

SELECT examples

Gets a query.

SELECT
id,
warehouse_id,
display_name,
last_modifier_user_name,
owner_user_name,
apply_auto_limit,
catalog,
create_time,
description,
lifecycle_state,
parameters,
parent_path,
query_text,
run_as_mode,
schema,
tags,
update_time
FROM databricks_workspace.sql.queries
WHERE id = '{{ id }}' -- required
AND deployment_name = '{{ deployment_name }}' -- required
;

INSERT examples

Creates a query.

INSERT INTO databricks_workspace.sql.queries (
auto_resolve_display_name,
query,
deployment_name
)
SELECT
{{ auto_resolve_display_name }},
'{{ query }}',
'{{ deployment_name }}'
RETURNING
id,
warehouse_id,
display_name,
last_modifier_user_name,
owner_user_name,
apply_auto_limit,
catalog,
create_time,
description,
lifecycle_state,
parameters,
parent_path,
query_text,
run_as_mode,
schema,
tags,
update_time
;

UPDATE examples

Updates a query.

UPDATE databricks_workspace.sql.queries
SET
update_mask = '{{ update_mask }}',
auto_resolve_display_name = {{ auto_resolve_display_name }},
query = '{{ query }}'
WHERE
id = '{{ id }}' --required
AND deployment_name = '{{ deployment_name }}' --required
AND update_mask = '{{ update_mask }}' --required
RETURNING
id,
warehouse_id,
display_name,
last_modifier_user_name,
owner_user_name,
apply_auto_limit,
catalog,
create_time,
description,
lifecycle_state,
parameters,
parent_path,
query_text,
run_as_mode,
schema,
tags,
update_time;

DELETE examples

Moves a query to the trash. Trashed queries immediately disappear from searches and list views, and

DELETE FROM databricks_workspace.sql.queries
WHERE id = '{{ id }}' --required
AND deployment_name = '{{ deployment_name }}' --required
;