Run NL2SQL

Execute the submitted SQL and return the result columns and string rows. This interface does not generate SQL.

HTTP
POST $CLOUDSIGMA_API_BASE/catalog/nl2sql/run_sql

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. First confirm the SQL statement and target database. Prepare the personal access token, target workspace ID, and SQL statement that can access the target workspace. This interface executes the submitted SQL. Please confirm the scope of influence of the statement before submitting.

Request body

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/catalog/nl2sql/run_sql" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "database_id": '"$DATABASE_ID"',
    "sql": "SELECT * FROM sales.orders LIMIT 10"
  }'

Field

Type

Required

Description

database_id

integer

No

Currently received but not used to select a database, it does not affect SQL execution.

sql

string

Yes

The SQL to execute.

This interface directly executes sql, does not use the model to generate or rewrite SQL, and is not limited to read-only SELECT. The service does not switch databases based on database_id.

Confirm the permissions and scope of the SQL before execution. When querying across databases, use fully qualified names, such as sales.orders.

Successful response

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "columns": [
      "id",
      "amount"
    ],
    "rows": [
      [
        "1",
        "100"
      ]
    ]
  }
}

Field

Type

Description

code

string

OK on success.

msg

string

OK on success.

data.columns

array of string

Result set column names.

data.rows

array or null

Result row, each cell is a string. May be null if there are no result rows.

Error response

JSON
{
  "code": "ErrServer",
  "msg": "服务器内部错误",
  "data": null
}

Field

Type

Description

code

string

error code.

msg

string

error message.

data

null

Additional data in the error response. This example is null.

Last updated on