Run NL2SQL¶
Execute the submitted SQL and return the result columns and string rows. This interface does not generate SQL.
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¶
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 |
|---|---|---|---|
|
integer |
No |
Currently received but not used to select a database, it does not affect SQL execution. |
|
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¶
{
"code": "OK",
"msg": "OK",
"data": {
"columns": [
"id",
"amount"
],
"rows": [
[
"1",
"100"
]
]
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
array of string |
Result set column names. |
|
array or null |
Result row, each cell is a string. May be null if there are no result rows. |
Error response¶
{
"code": "ErrServer",
"msg": "服务器内部错误",
"data": null
}
Field |
Type |
Description |
|---|---|---|
|
string |
error code. |
|
string |
error message. |
|
null |
Additional data in the error response. This example is |