Executing SQL Statements Under a Specified Session
Function
This API is used to execute SQL statements under a specified session.
This API supports both synchronous and asynchronous execution modes, determined by the input parameter is_sync. For asynchronous execution, use the Viewing SQL Execution Results API to query the result.
For synchronous execution, the API waits to receive the result. If execution is complete, the result is returned. If not, a running status is returned, and you can use the Viewing SQL Execution Results API to query the result.
Calling Method
For details, see Calling APIs.
URI
POST /v2/workspaces/{workspace_id}/aura-sessions/statements
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| workspace_id | Yes | String | Definition: Workspace ID. For details about how to obtain the workspace ID, see Obtaining a Workspace ID. Constraints: N/A Range: 1 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition: User token. It is obtained by calling the Obtaining an IAM User Token API. Constraints: N/A Range: N/A Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| session_id | Yes | String | Definition: Session ID. You can obtain the session ID by calling the Listing Sessions API. Constraints: N/A Range: 1 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
| statement | Yes | String | Definition: SQL statement. Constraints: N/A Range: 1 to 10,000,000 characters. Default Value: N/A |
| limit | No | Integer | Definition: Maximum number of rows to return in the result set. Constraints: N/A Range: 1 to 2,147,483,647, in rows. Default Value: N/A |
| bindings | No | Array<Array<String>> | Definition: Parameter binding list for SQL statements, used for bound variable passing. The outer array is the binding set (only bindings[0] is used in practice). The inner array is the parameter value list for a single SQL statement, where each string element represents a single parameter value. Constraints Range: N/A Default Value: N/A |
| is_sync | No | Boolean | Definition: Whether an execution is synchronous or asynchronous. Constraints: N/A Range Default Value: true (sync by default if not specified). |
| resultset_fetch_mode | No | String | Definition: Method for retrieving the result set. Constraints: N/A Range
Default Value: DEFAULT. |
| wait_timeout | No | Integer | Definition: SQL queue wait timeout, in seconds. Constraints: N/A Range: 300 to 86,400. Default Value: N/A |
| max_retry_times | No | Integer | Definition: Number of retry attempts when resources are insufficient. Constraints: N/A Range: 1 to 6,000. Default Value: N/A |
| statement_type | No | String | Definition: Job type. Constraints: N/A Range Default Value: SQL |
| statement_name | No | String | Definition: Job name. Constraints: Up to 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. Range: N/A Default Value: N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| status | Integer | Definition: Statement status. Range |
| session_id | String | Definition: Session ID. Range: 1 to 36 characters. Only letters, digits, and hyphens (-) are allowed. |
| statement_id | String | Definition: Statement ID. Range: 1 to 36 characters. Only letters, digits, and underscores (_) are allowed. |
| results | Array of results objects | Definition: List of statement execution results, returned in the order of execution. |
| Parameter | Type | Description |
|---|---|---|
| status | String | Definition: SQL execution result status. Range: PGRES_TUPLES_OK (query successful with result set), PGRES_COMMAND_OK (command executed successfully without result set), PGRES_FATAL_ERROR (query failure). |
| statement_id | String | Definition: Unique identifier of this statement execution. Range: UUID. |
| num_rows | Long | Definition: Number of rows in the result set. Range: N/A |
| row_count | Long | Definition: Number of affected rows. Range: N/A |
| page_count | Integer | Definition: Total number of pages. Range: N/A |
| page_no | Integer | Definition: Current page number. Range: N/A |
| err_code | String | Definition: Error code. Range: 0 (success). |
| sql_state | String | Definition: SQL status code. Range: N/A |
| message | String | Definition: Execution message. |
| result_set | result_set object | Definition: Result set. Contains valid data only when the query succeeds (PGRES_TUPLES_OK). Otherwise, it is an empty object {}. |
| Parameter | Type | Description |
|---|---|---|
| columns | Array of columns objects | Definition: Column metadata list. |
| rows | Array<Array<String>> | Definition: Actual data rows. The order of each row corresponds to the columns. |
| Parameter | Type | Description |
|---|---|---|
| name | String | Definition: Column name. Range: 1 to 64 characters. |
| table_id | Integer | Definition: Table ID. |
| column_id | Integer | Definition: Column ID. |
| format | Integer | Definition: Format. |
| type | Integer | Definition: Column type OID. |
| size | Integer | Definition: Column size. |
| type_mod | Integer | Definition: Type modifier. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Status code: 404
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Status code: 408
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Range: 8 to 36 characters. |
| error_msg | String | Definition: Error description. Range: 2 to 4,096 characters. |
| solution_msg | String | Definition: Solution description. Range: 2 to 4,096 characters. |
Example Requests
Execute SQL statements under a specified session.
POST /v2/workspaces/{workspace_id}/aura-sessions/statements
{
"statement" : "select * from aaa",
"limit" : 100,
"session_id" : "6399466e-8908-xxxx-xxxx-48479c8b06f7",
"bindings" : [ [ "string" ] ],
"resultset_fetch_mode" : "DEFAULT",
"is_sync" : true
} Example Responses
Status code: 200
{
"status" : 0,
"session_id" : "6399466e-8908-4c9d-8399-48479c8b06f7",
"statement_id" : "49131d25-1824-4f29-860c-832bdd19dfd3",
"results" : [ {
"status" : "PGRES_TUPLES_OK",
"statement_id" : "49131d25-1824-4f29-860c-832bdd19dfd3",
"num_rows" : 1,
"row_count" : 1,
"page_count" : 1,
"page_no" : 1,
"err_code" : "0",
"sql_state" : "0",
"message" : "CREATE SCHEMA",
"result_set" : {
"columns" : [ {
"name" : "a",
"table_id" : 0,
"column_id" : 1,
"format" : 0,
"type" : 23,
"size" : 4,
"type_mod" : -1
} ],
"rows" : [ [ "1" ] ]
}
} ]
} Status code: 400
{
"error_code" : "AIDataLake.00092031",
"error_msg" : "Invalid parameter name",
"solution_msg" : "Please enter parameters in the correct format."
} Status code: 401
{
"error_code" : "APIG.1002",
"error_msg" : "Incorrect token or token resolution failed.",
"solution_msg" : "Please obtain a valid token and retry."
} Status code: 403
{
"error_code" : "AIDataLake.00090030",
"error_msg" : "Unauthorized requests.",
"solution_msg" : "Check permissions and retry after authorization."
} Status code: 404
{
"error_code" : "AIDataLake.00090009",
"error_msg" : "The resource does not exists.",
"solution_msg" : "Please try to use correct info."
} Status code: 408
{
"error_code" : "common.00000408",
"error_msg" : "A timeout exception occurred.",
"solution_msg" : "The request timed out while waiting for a response — check the backend service status and network, then retry; if the operation is long-running, increase the client timeout or split the request."
} Status code: 500
{
"error_code" : "common.00000500",
"error_msg" : "internal error",
"solution_msg" : "An internal service error occurred. Please retry later; if the problem persists, contact technical support."
} Status Codes
| Status Code | Description |
|---|---|
| 200 | Request succeeded. |
| 400 | Invalid request. |
| 401 | Unauthorized. |
| 403 | Request denied. |
| 404 | The requested resource could not be found. |
| 408 | Request timeout. |
| 500 | Internal server error. |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot