Introducing Chat2Query: An Innovative AI-Powered SQL Generator for Faster Insights
Tags: ai, tidb, database, chatgpt
Published: 2023-03-15 08:09:11

We are excited to introduce Chat2Query (beta), a revolutionary natural language query generator powered by Pre-trained Transformer 3 (GPT-3), the technology behind ChatGPT, and TiDB, the distributed SQL database.

With Chat2Query, you don’t need to be an SQL expert to extract insights from your data. Simply ask a question and the AI tool will do the rest, generating a powerful SQL query to retrieve the insights. By combining OpenAI and TiDB, we utilize AI to innovate the database and aid in data exploration, providing real-time and actionable insights for instant business decisions.

In this post, we’ll show you how to get started with the AI-powered Chat2Query and explore insights through sample datasets and your own datasets.

## More than just another AI-powered SQL generator
Yes, there are several AI-powered SQL generators available that can help users generate SQL queries without needing to have extensive knowledge of the SQL language. However, these AI tools are best suited for generating simple queries. This means they may not be suitable for more complex tasks or production use.

Chat2Query is powered by:

- OpenAI’s GPT3, the industry-leading natural language-to-code processing model and the technology behind the viral ChatGPT.

- TiDB Cloud Serverless Tier, the Hybrid Transactional and Analytical Processing (HTAP) database service that enables developers to deploy their infrastructure at scale in the most cost-efficient way without managing server infrastructure.

By using these two technologies, Chat2Query can handle even the most complex queries and offer real-time insights into dynamic datasets.
## Query on the Netflix dataset – tell me the best 10 Netflix titles.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp8pokop2bs2iyhtcnvy.gif)
## Query on a Web3 dataset – in which month of last year did the highest volumehappen?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abbhff8gehzukd2migyd.gif)
## Get started with Chat2Query
Chat2Query is an integrated feature in TiDB Cloud Serverless Tier. You can take the following steps to get started:
### Step 1: Sign in to your Serverless Tier cluster.
[Sign up](https://tidbcloud.com/free-trial?utm_source=blog-chat2query&utm_medium=referral&utm_campaign=chat2query_202301&__hstc=86493575.222bb597bbf6a72a4c1331f4b1e00550.1678789693103.1678789693103.1678864410972.2&__hssc=86493575.1.1678864410972&__hsfp=1777525318&_ga=2.154618554.384657226.1678789689-144949394.1673941825) for a TiDB Cloud account using your email, Google account, or GitHub account. Your Serverless Tier cluster will be created automatically in less than 20 seconds, and you will be directed to the Chat2Query interface.

### Step 2: Prepare your datasets.
You can either use the sample datasets to quickly explore Chat2Query or explore insights on your own datasets.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60d3dyw4bazhbxg9ec54.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rpykq1sgomb2jzbgbfz.png)
### Step 3: Explore insights with Chat2Query.
1. Generate the query. In the Chat2Query editor, type in “– your question” and click Enter to let AI generates the query in SQL.
2. Review the query. Press the Tab key to accept the SQL or edit it as necessary before accepting.
3. Run your query. In the top right-hand corner of the screen, click the play button. The query results are displayed at the bottom of the page.
You will see the query logs and results immediately at the bottom of the page. For sample output, see **Exploring sample uses.**
## Built with security and privacy
The privacy and security of user data is our top priority. We understand that our users trust us to protect their information and we take that responsibility seriously. As a query service on TiDB Cloud, Chat2Query only needs to access your database schema to generate SQL, and not your actual data.
## Limitations
As a beta project, Chat2Query is still in development with a lot of room for improvement. Therefore, there are two limitations to keep in mind:

1. The AI-generated SQL is not always 100% correct and may still need further tweaking.
2. Chat2Query has limited support for SQL statements. DDL statements such as 

```
CREATE TABLE
```
 and 

```
DROP TABLE
```
 are not supported yet.
## Get started withChat2Querytoday

You can obtain early access [here](https://tidbcloud.com/?__hstc=86493575.222bb597bbf6a72a4c1331f4b1e00550.1678789693103.1678789693103.1678864410972.2&__hssc=86493575.1.1678864410972&__hsfp=1777525318&_ga=2.218064532.384657226.1678789689-144949394.1673941825). We’d love to hear your feedback so we can make this query tool even better.

In the meantime, Chat2Query is in rapid development. Please follow us on [Twitter](https://twitter.com/pingcap) to stay up-to-date on its progress.