This API converts a natural language description into an executable SQL statement by retrieving relevant database and business information.
Operation description
In addition to the generated SQL statement, the result provides other useful information, such as the tables used, related concepts, and similar SQL.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
dms:GenerateSqlFromNL |
none |
*All Resource
|
None | None |
Request syntax
POST / HTTP/1.1
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| DbId |
string |
Yes |
The database ID. You can call the ListDatabases operation to obtain this ID. The API operation uses the schema from this database to generate the SQL statement. |
1*** |
| Knowledge |
string |
No |
Supplementary business information to help the model better understand the question. |
state>0代表成功 |
| Question |
string |
Yes |
The natural language question to convert into an SQL statement. |
查询今天的用户访问量 |
| Dialect |
string |
No |
The SQL dialect. If unspecified, the system defaults to |
MySQL |
| Level |
string |
No |
The processing level. The default value is |
base |
| Model |
string |
No |
The Qwen series model to use. |
qwen-plus |
| TableNames |
string |
No |
A comma-separated list of table names. If specified, the model uses only these tables to generate the SQL statement. |
users,orders |
| RealLoginUserUid |
string |
No |
The Alibaba Cloud account ID of the user who calls the operation. |
21400447956867**** |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The data returned in the response. |
||
| RequestId |
string |
The request ID. You can use this ID to locate logs and troubleshoot issues. |
0C1CB646-1DE4-4AD0-B4A4-7D47DD52E931 |
| ErrorCode |
string |
The error code. |
UnknownError |
| ErrorMessage |
string |
The error message. |
UnknownError |
| Success |
boolean |
Indicates whether the request was successful.
|
true |
| Data |
object |
The returned data. |
|
| Question |
string |
The natural language question provided as input. |
查询今天用户访问量 |
| Tables |
array<object> |
A list of tables used to generate the SQL statement. |
|
|
object |
A table object. Each object represents a specific table and includes information such as the table name and table ID. |
||
| TableName |
string |
The name of the table. |
ins_1.db1.table1 |
| KnowledgeReferences |
array<object> |
A list of knowledge items referenced during SQL generation. |
|
|
object |
A knowledge item. |
||
| Name |
string |
The name of the knowledge item. |
sample_tbl |
| Content |
string |
The content of the knowledge item. |
{'Status': 'OK'} |
| Level |
string |
The status of the knowledge item. Valid values include Valid values:
|
verified |
| Sql |
string |
The generated SQL statement. |
SELECT * FROM table WHERE condition; |
| SimilarSql |
array<object> |
A list of similar SQL statements. |
|
|
object |
Information about a similar SQL statement. |
||
| Question |
string |
The natural language question. |
实例xxx的访问量有多少? |
| Sql |
string |
A similar SQL statement. |
SELECT * WHERE ResourceType = 'ACS::ECS::Instance' AND ResourceGroupId != 'rg-xxx' |
| Thought |
string |
The thought process used to generate the SQL statement. |
度量(指标): 用户询问了xx指标,根据上下文,需要计算xxx。 维度(筛选条件): 用户问题里提到了xx的条件,结合上下文,核心维度为xxx。 综上,需要使用xxx表,使用xxx列。其中xxx作为projection选择,xxx用于过滤条件,xxx用于分组条件。 |
| Score |
string |
The confidence score for the generated SQL statement, ranging from 0 to 1. A higher score indicates greater confidence. |
0.52 |
| Thought |
string |
The thought process used to generate the SQL statement. |
通过分析用户的问题和提供的知识,生成了相应的SQL语句。 |
Examples
Success response
JSON format
{
"RequestId": "0C1CB646-1DE4-4AD0-B4A4-7D47DD52E931",
"ErrorCode": "UnknownError",
"ErrorMessage": "UnknownError",
"Success": true,
"Data": {
"Question": "查询今天用户访问量",
"Tables": [
{
"TableName": "ins_1.db1.table1"
}
],
"KnowledgeReferences": [
{
"Name": "sample_tbl",
"Content": "{'Status': 'OK'}",
"Level": "verified"
}
],
"Sql": "SELECT * FROM table WHERE condition;",
"SimilarSql": [
{
"Question": "实例xxx的访问量有多少?",
"Sql": "SELECT * WHERE ResourceType = 'ACS::ECS::Instance' AND ResourceGroupId != 'rg-xxx'",
"Thought": "度量(指标): 用户询问了xx指标,根据上下文,需要计算xxx。\n维度(筛选条件): 用户问题里提到了xx的条件,结合上下文,核心维度为xxx。\n综上,需要使用xxx表,使用xxx列。其中xxx作为projection选择,xxx用于过滤条件,xxx用于分组条件。",
"Score": "0.52"
}
],
"Thought": "通过分析用户的问题和提供的知识,生成了相应的SQL语句。"
}
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.