How can you go to the text to SQL with llms


Photo for Author | Kanele
With large lagnuage models (lls), everyone is a code today! This is a message you receive in the Ill promos. Obviously not true, like any advertisement. Codes that are more than generating code in the freakneck speed. However, translation English (or other ecclesiologists) in the SQL questions is one of the force of the llms, and has its place in the world.
Obvious Why did you use the llms to produce SQL?
There are several benefits to use the llms to produce SQL, and, as everything, there is something.

Obvious Two Scriptural Types-To-SQL LLMS
We can distinguish between the two most broad varieties of text technology – to the SQL currently available about their access to your data schema.
- Llms without direct access
- Llms with direct access
// 1. llms without direct access to data schema
These llms do not connect or issue questions against real information. The closest you can find to load the datasets you want to ask. These tools rely on you in giving the context about your schema.
The Lotor's Examples:
Use charges:
- Question to write and Protymping
- Literacy
- Code of visual code for later review
// 2. Llms with direct access to data schemase
These lls are directly connected to your live data resources, such as postgresql, snow ice, biobquery, or redshift. They allow you to produce, remove, and return results from the live SQL Qieries in your database.
The Lotor's Examples:
Use charges:
- Changed analysis of business users
- Real-time data test
- Embodied by AI assistance on the Bi platforms
Obvious Step-In step: How to go to the text to SQL
The basic job movement of receiving SQL from the text is the same, whether you use the connected or connected llms.

We will try to solve the chat question from the shophiff and Amazon using the above steps in ChatGPT.
// 1. Describe Schema
For a question to work in your data, the llm needs to understand your data formation clearly. This usually includes:
- Tires in the table
- Words in the column and kinds
- Relationship between tables (Jouins, Keys)
This information can be transmitted directly when it is promptly or can be obtained by the Vector search within the remote-Augmented Generagned Generagnet Generagneted Generagneted (Rag) Pipeline.
// 2. Soon in natural language
Prompt will include two parts:
- SCHEMA Description
- Question (s) that requires SQL response
Example: Let me start to give you a quick building that includes planners. We will then write the presence.
We will use a role playlist, which means teaching Chatgpt to take a specific role.
Here's how you plan quickly.
Dataset: My dataset consists of [number of tables] tables.
The first one is [table “” not found /]
with the following columns and data types:
[column names and data types]
The second table is [table “” not found /]
with the following columns and data types:
[column names and data types]
Question: [provide a question to be answered]
Assumptions: [provide assumptions for solving the question]
Role: [describe a role LLM has to play]
Let us now write fast to solve our chat questions.
Here is, and we hope that it will give the right solution of SQL. Column names, data types, question, and consideration simply passes the question itself.
Dataset: My dataset consists of two tables.
The first one is "customers" with the following columns and data types:
address:
text
city:
text
first_name:
text
id:
bigint
last_name:
text
phone_number:
text
The second table is "orders" with the following columns and data types:
cust_id:
bigint
id:
bigint
order_date:
date
order_details:
text
total_order_cost:
bigint
Question: Find the customers with the highest daily total order cost between 2019-02-01 and 2019-05-01. If a customer had more than one order on a certain day, sum the order costs on a daily basis. Output each customer's first name, total cost of their items, and the date.
Assumption: For simplicity, you can assume that every first name in the dataset is unique.
Role: Act as a SQL expert and write a PostgreSQL query that answers the question.
// 3. Produce SQL question
At this stage, your choice of choice produces a SQL question.
Example: Here is the Postgresql Chatgpt code produced.
SELECT
c.first_name,
daily_totals.order_date,
daily_totals.total_cost
FROM (
SELECT
cust_id,
order_date,
SUM(total_order_cost) AS total_cost
FROM orders
WHERE order_date BETWEEN '2019-02-01' AND '2019-05-01'
GROUP BY cust_id, order_date
) AS daily_totals
JOIN customers c ON c.id = daily_totals.cust_id
WHERE (daily_totals.cust_id, daily_totals.order_date) IN (
SELECT
cust_id,
order_date
FROM (
SELECT
cust_id,
order_date,
SUM(total_order_cost) AS total_cost,
RANK() OVER (ORDER BY SUM(total_order_cost) DESC) AS rnk
FROM orders
WHERE order_date BETWEEN '2019-02-01' AND '2019-05-01'
GROUP BY cust_id, order_date
) ranked
WHERE rnk = 1
);
// 4. Make a question
Now, you can issue a question, it can be exactly (if your llm supports live connections) or by copying and activate your data system.
For example: In our case, we will copy the code in the Stratascratch Code editor and use the 'Check Solution “button to confirm the solution.
This is what outgoing, and it is a proper solution. ChatGpt Bravy! He is initially named after you try!
| name | Order_date | Total_cost |
|---|---|---|
| Frustrate | 2019-04-19 | 275 |
| Set | 2019-04-19 | 275 |
// 5. Review, imagine, and sanctified
It also depends on the purpose of lls to write the SQL code, this step may be voluntary. In the business world, you would have revealed the question in easy-useful format, which involves:
- Displays results as a table and / or chart
- Allowing Following Needs (eg, “You can add Customer City?”) And to provide a changed question
Obvious Pamphlets and the best habits
In our example, Chatgpt came quickly and the correct answer. However, it does not mean that, especially when data and needs are more complex. Using the LLMS for SQL questions in the text is not without the pitfalls. You can avoid using more activities better if you want to make a llM generation a part of your data science work.

Obvious Store
The llms can be your best friend when you want to create SQL questions in the text. However, doing good in these tools, you must have a clear understanding of what you want to achieve and charges of using llms is beneficial.
This article gives such guidance, as well as an example of how to awaken the LLM into the natural language and get active SQL code.
Nate Rosid He is a data scientist and product plan. He is a person who is an educated educator, and the Founder of Stratascratch, a stage that helps data scientists prepare their conversations with the highest discussion of the chat. Nate writes the latest stylies in the work market, offers chat advice, sharing data science projects, and covered everything SQL.



