Skip to content

Latest commit

 

History

History
110 lines (64 loc) · 6.55 KB

explore-data-with-chat2query.md

File metadata and controls

110 lines (64 loc) · 6.55 KB
title summary
Explore Your Data with AI-Powered Chat2Query (beta)
Learn how to use Chat2Query, an AI-powered SQL editor in the TiDB Cloud console, to maximize your data value.

Explore Your Data with AI-Powered Chat2Query (beta)

TiDB Cloud is powered by AI. You can use Chat2Query (beta), an AI-powered SQL editor in the TiDB Cloud console, to maximize your data value.

In Chat2Query, you can either simply type -- followed by your instructions to let AI generate SQL queries automatically or write SQL queries manually, and then run SQL queries against databases without a terminal. You can find the query results in tables intuitively and check the query logs easily.

Note:

Chat2Query is only available for Serverless Tier clusters.

Use cases

The recommended use cases of Chat2Query are as follows:

  • Use the AI capacity of Chat2Query to help you generate complex SQL queries instantly.
  • Test out the MySQL compatibility of TiDB quickly.
  • Explore TiDB SQL features easily.

Limitation

SQL queries generated by the AI are not 100% accurate and might still need your further tweak.

Access Chat2Query

  1. Go to the Clusters page of your project.

    Tip:

    If you have multiple projects, you can switch to the target project in the left navigation pane of the Clusters page.

  2. Click your cluster name, and then click Chat2Query in the left navigation pane.

Enable or disable AI to generate SQL queries

PingCAP takes the privacy and security of users' data as a top priority. The AI capacity of Chat2Query only needs to access database schemas to generate SQL queries, not your data itself. For more information, see Chat2Query Privacy FAQ.

When you access Chat2Query for the first time, you will be prompted with a dialog about whether to allow PingCAP and OpenAI to use your code snippets to research and improve the services.

  • To enable the AI to generate SQL queries, select the checkbox and click Save and Get Started.
  • To disable the AI to generate SQL queries, close this dialog directly.

After the first-time access, you can still change the AI setting as follows:

  • To enable AI, click Enable AI power for data exploration in the upper-right corner of Chat2Query.
  • To disable AI, click Account in the upper-right corner of the TiDB Cloud console, click Account Settings, click the Privacy tab, and then disable the AI-powered Data Exploration option.

Write and run SQL queries

In Chat2Query, you can write and run SQL queries using the pre-built sample dataset or your own dataset.

  1. Write SQL queries.

    • If AI is enabled, simply type -- followed by your instructions to let AI generate SQL queries automatically or write SQL queries manually.

      For a SQL query generated by AI, you can accept it by pressing Tab and then further edit it if needed, or reject it by pressing Esc.

    • If AI is disabled, write SQL queries manually.

  2. Run SQL queries.

    For macOS:

    • If you have only one query in the editor, to run it, press ⌘ + Enter or click Run.

    • If you have multiple queries in the editor, to run one or several of them sequentially, select the lines of the target queries with your cursor, and then press ⌘ + Enter or click Run.

    • To run all queries in the editor sequentially, press ⇧ + ⌘ + Enter, or select the lines of all queries with your cursor and click Run.

    For Windows or Linux:

    • If you have only one query in the editor, to run it, press Ctrl + Enter or click Run.

    • If you have multiple queries in the editor, to run one or several of them sequentially, select the lines of the target queries with your cursor, and then press Ctrl + Enter or click Run.

    • To run all queries in the editor sequentially, press Shift + Ctrl + Enter, or select the lines of all queries with your cursor and click Run.

After running the queries, you can see the query logs and results immediately at the bottom of the page.

Manage SQL files

In Chat2Query, you can save your SQL queries in different SQL files and manage SQL files as follows:

  • To add a SQL file, click + on the SQL Files tab.
  • To rename a SQL file, move your cursor on the filename, click ... next to the filename, and then select Rename.
  • To delete a SQL file, move your cursor on the filename, click ... next to the filename, and then select Delete. Note that when there is only one SQL file on the SQL Files tab, you cannot delete it.

Manage Chat2Query settings

By default, Chat2Query limits the maximum number of rows in query results to 500 and does not show system database schemas on the Schemas tab.

To change the settings, take the following steps:

  1. In the upper-right corner of Chat2Query, click ... and select Settings.
  2. Change the settings according to your need.
  3. Click Save.