Databricks AI SQL Functions: AI_GENERATE, AI_QUERY, AI_CLASSIFY
Data teams spend a significant amount of time writing SQL queries, analyzing datasets, and classifying data manually. Even experienced analysts face challenges when working with complex queries or large tables.
Databricks AI SQL functions—including AI_GENERATE, AI_QUERY, and AI_CLASSIFY—bring AI-powered intelligence directly into SQL, enabling teams to generate queries, get insights, and classify data using natural language or AI models.
Why AI SQL Functions Matter
Imagine an analyst who wants to:
- Generate a summary report of quarterly sales.
- Classify customer feedback into positive, negative, or neutral sentiment.
- Write a complex join query without manually coding it.
Without AI SQL functions:
- Queries are time-consuming and error-prone
- Large datasets make manual inspection difficult
- Collaboration slows down due to repetitive tasks
With Databricks AI SQL functions:
- AI_GENERATE: Generates SQL from natural language instructions
- AI_QUERY: Summarizes, answers questions, or extracts insights from SQL tables
- AI_CLASSIFY: Classifies data automatically based on AI models
How Databricks AI SQL Functions Work
- AI_GENERATE: Converts natural language instructions into SQL queries.
- AI_QUERY: Queries datasets intelligently, returning results or insights.
- AI_CLASSIFY: Automatically labels or categorizes data using AI models.
- Seamless Integration: Functions work directly in Databricks SQL, notebooks, or dashboards.
Example 1: AI_GENERATE
Instruction:
SELECT AI_GENERATE('Get total revenue per region for Q4 2025')
Generated SQL Output:
SELECT region, SUM(revenue) AS total_revenue
FROM sales_data
WHERE sale_date BETWEEN '2025-10-01' AND '2025-12-31'
GROUP BY region
ORDER BY total_revenue DESC;
Example Result Table:
| region | total_revenue |
|---|---|
| North | 1,200,000 |
| South | 950,000 |
| East | 870,000 |
Example 2: AI_QUERY
SELECT AI_QUERY('Which products had the highest increase in sales compared to last quarter?', 'sales_data')
Example Output Table:
| product | revenue_change |
|---|---|
| Electronics | 25% |
| Home Appliances | 18% |
This allows analysts to get insights without manually calculating differences or writing complex queries.
Example 3: AI_CLASSIFY
Suppose you have a customer_feedback table:
SELECT AI_CLASSIFY(feedback, 'Sentiment: Positive, Negative, Neutral') AS sentiment
FROM customer_feedback
Input Table:
| feedback |
|---|
| "Great service, very satisfied" |
| "Product arrived broken" |
| "Delivery was okay" |
Output Table:
| feedback | sentiment |
|---|---|
| "Great service, very satisfied" | Positive |
| "Product arrived broken" | Negative |
| "Delivery was okay" | Neutral |
AI_CLASSIFY automates data labeling, saving time and ensuring consistency.
Key Benefits of Databricks AI SQL Functions
| Function | Benefit |
|---|---|
| AI_GENERATE | Write complex SQL queries from natural language instantly |
| AI_QUERY | Get insights and answers from datasets automatically |
| AI_CLASSIFY | Automatically categorize and label data |
| Seamless Integration | Works directly in SQL, notebooks, and dashboards |
| Faster Insights | Reduce manual work and accelerate analysis |
Summary
Databricks AI SQL functions bring AI directly into SQL workflows, enabling teams to generate queries, gain insights, and classify data efficiently. By leveraging AI_GENERATE, AI_QUERY, and AI_CLASSIFY, analysts and engineers can focus on decision-making rather than repetitive tasks, improving productivity and accelerating data-driven outcomes.
The next topic is “Databricks DBRX LLM — What It Means for Data Engineers”.