Skip to main content

statements

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

Overview

Namestatements
TypeResource
Idsnowflake.sqlapi.statements

Fields

The following fields are returned by SELECT queries:

The statement was executed successfully, and the response includes any data requested.

NameDatatypeDescription
codestring (example: 000123)
createdOninteger (int64)Timestamp that specifies when the statement execution started.‌ The timestamp is expressed in milliseconds since the epoch.‌
dataarrayResult set data.
messagestring (example: successfully executed)
resultSetMetaDataobject
sqlStatestring (example: 42601)
statementHandlestring (uuid) (example: 536fad38-b564-4dc5-9892-a4543504df6c)
statementStatusUrlstring (uri)
statsobjectthese stats might not be available for each request.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_statement_statusselectstatement_handle, endpointrequestId, partitionChecks the status of the execution of the statement with the specified statement handle. If the statement was executed successfully, the operation returns the requested partition of the result set.
submit_statementinsertendpointrequestId, async, nullableSubmits one or more statements for execution. You can specify that the statement should be executed asynchronously.
cancel_statementdeletestatement_handle, endpointrequestIdCancels the execution of the statement with the specified statement handle.

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
endpointstringOrganization and account identifier (orgname-accountname) (default: orgname-accountname)
statement_handlestring (uuid)The handle of the statement that you want to use (e.g. to fetch the result set or cancel execution).
asyncbooleanSet to true to execute the statement asynchronously and return the statement handle. If the parameter is not specified or is set to false, a statement is executed and the first result is returned if the execution is completed in 45 seconds. If the statement execution takes longer to complete, the statement handle is returned.
nullablebooleanSet to true to execute the statement to generate the result set including null. If the parameter is set to false, the result set value null will be replaced with a string 'null'.
partitioninteger (int64)Number of the partition of results to return. The number can range from 0 to the total number of partitions minus 1.
requestIdstring (uuid)Unique ID of the API request. This ensures that the execution is idempotent. If not specified, a new UUID is generated and assigned.

SELECT examples

Checks the status of the execution of the statement with the specified statement handle. If the statement was executed successfully, the operation returns the requested partition of the result set.

SELECT
code,
createdOn,
data,
message,
resultSetMetaData,
sqlState,
statementHandle,
statementStatusUrl,
stats
FROM snowflake.sqlapi.statements
WHERE statement_handle = '{{ statement_handle }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND requestId = '{{ requestId }}'
AND partition = '{{ partition }}'
;

INSERT examples

Submits one or more statements for execution. You can specify that the statement should be executed asynchronously.

INSERT INTO snowflake.sqlapi.statements (
statement,
timeout,
"database",
"schema",
warehouse,
role,
bindings,
parameters,
endpoint,
requestId,
async,
nullable
)
SELECT
'{{ statement }}',
{{ timeout }},
'{{ database }}',
'{{ schema }}',
'{{ warehouse }}',
'{{ role }}',
'{{ bindings }}',
'{{ parameters }}',
'{{ endpoint }}',
'{{ requestId }}',
'{{ async }}',
'{{ nullable }}'
RETURNING
code,
createdOn,
data,
message,
resultSetMetaData,
sqlState,
statementHandle,
statementStatusUrl,
stats
;

DELETE examples

Cancels the execution of the statement with the specified statement handle.

DELETE FROM snowflake.sqlapi.statements
WHERE statement_handle = '{{ statement_handle }}' --required
AND endpoint = '{{ endpoint }}' --required
AND requestId = '{{ requestId }}'
;