Execute SQL

Execute SQL and save execution records. The query ID is returned on success, which can be used to query status and read saved results.

HTTP
POST $CLOUDSIGMA_API_BASE/query/execute

Before you call

Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. Prepare personal access token and target workspace ID that can access the target workspace.

The calling identity requires appropriate permissions on the target database and the object referenced by the SQL. Don’t splice unprocessed user input directly into SQL.

Request body

Replace $CLOUDSIGMA_API_KEY, $WORKSPACE_ID, and the database name, SQL in the example with actual values.

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/query/execute" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "db_name": "sales",
    "query": "SELECT 1 AS n",
    "offset": 0,
    "limit": 20
  }'

Parameter

Type

Required

Description

db_name

string

No

The database used when executing SQL.

query

string

Yes

The SQL to execute.

sql_type

string

No

Currently, it only receives and passes the identifier, and does not participate in SQL execution or change the execution mode.

offset

integer

No

The starting position of the first results window.

limit

integer

No

Returns the number of rows in the result window. For specific boundaries, see “Result Window” below.

results window

offset specifies the starting point of the results. When it is less than 1000, the upper limit of the result window is min(1000, 1000-offset). When limit is greater than 0 and less than the upper limit of the window, use limit, otherwise use the upper limit of the window.

When the current offset is greater than or equal to 1000, the upper limit calculation result is 0, and the service may continue to scan the remaining rows. Therefore, 1000 cannot be considered a strict scan upper limit.

Successful response

JSON
{
  "code": 200,
  "data": {
    "id": "query_01",
    "query_id": "query_01"
  }
}

Field

Type

Description

code

integer

200 on success.

data

object

Query ID.

data.id

string

Query ID, same as query_id.

data.query_id

string

Query ID. Used to check status or cancel execution.

Error response

JSON
{
  "code": 400,
  "message": "请求参数无效"
}

Field

Type

Description

code

integer or string

SQL processing errors may be numeric status codes. Authentication or general service errors may be string error codes.

message

string

error message.

Errors are encapsulated in two ways: The SQL processing path uses {“code”:400,”message”:”…”}. Authentication or general service error using {“code”:”ErrServer”,”msg”:”…”}. Both message and msg are readable error messages, which should be read based on the actual fields and cannot be judged only by the numerical code.

Last updated on