Skip to main content

Natural Language Generation of SQL

Overview

AskTable provides an API interface for generating SQL. Through this API, developers can use AskTable's natural language processing capabilities to automatically generate SQL, thus meeting various specific scenarios.

Applicable Scenarios:

  1. Developers do not want to implement different question-answering logics for different user needs, and want to provide a unified query service through a single page.
  2. Developers do not want to use AskTable's UI interface, but want to implement their own UI interface.
  3. Developers want to access the database themselves, rather than through AskTable.

Python SDK Example

If you are a Python developer, you can directly use the Python SDK to generate SQL, which is very convenient. The specific example code is as follows:

# Example of generating SQL code:
from asktable import Asktable

api_key = "<ASKTABLE_API_KEY>"
asktable_client = Asktable(api_key=api_key)

datasource_id = "ds_2Ds3Ude2MkFAWvyVSRG"
question = "How many orders are there?"
query_response = asktable_client.sqls.create(datasource_id=datasource_id, question=question)

print(query_response.query.sql)

Summary

Through the SQL generation API provided by AskTable, users can conveniently use natural language to make query requests and obtain corresponding SQL query strings. This approach not only simplifies the query process, but also ensures data security and privacy, avoiding data leaving the company's internal network.

For more questions about the SQL generation process, please visit AskTable Natural Language Query Database for detailed information.