Skip to main content

Overview

The SQL Editor in Quail provides a powerful environment for writing and executing SQL queries with intelligent auto-completion, AI assistance, and built-in visualization capabilities.

Getting Started

1

Open SQL Editor

Navigate to SQL Editor from the main navigation menu.
2

Select Database Connection

Choose a database connection from the dropdown menu at the top of the editor. If you haven’t created a connection yet, see the Database Connections guide.
3

Start Writing

The editor will load with your connection’s schema information available in the left sidebar. You can now start writing SQL queries.

Writing SQL Queries

Basic Query Structure

Start with a simple SELECT query to explore your data:
SELECT * FROM customers LIMIT 10;
This returns the first 10 rows from your customers table.
It’s a good practice to include a LIMIT clause when exploring new tables to avoid accidentally fetching large datasets.

Using the Schema Explorer

The left sidebar contains the Schema Explorer, which helps you navigate your database structure:

Browse Tables

View all available tables and views in your database. Tables are organized by schema if applicable.

View Columns

Click on any table to expand it and see all columns with their data types.

Quick Insert

Click the + icon next to a column name to automatically insert it into your query at the cursor position.

Quick Actions

Right-click on a table for quick actions:
  • SELECT * FROM table
  • SELECT COUNT(*) FROM table
  • DESCRIBE table

Auto-Completion

The SQL Editor provides intelligent auto-completion to speed up your query writing:
Start typing a table name and press Tab to auto-complete. The editor shows matching tables from your schema.
SELECT * FROM cus[Tab] -- completes to "customers"

Running Queries

1

Write Your Query

Type or paste your SQL query into the editor.
2

Execute

Click the Run button or use the keyboard shortcut:
  • Windows/Linux: Ctrl + Enter
  • Mac: Cmd + Enter
3

View Results

Query results appear in the results panel below the editor, showing:
  • Data table with all returned rows
  • Number of rows returned
  • Query execution time
  • Any errors or warnings
You can run multiple queries in sequence by separating them with semicolons. The editor will execute them one at a time and show results for each.

AI-Assisted Query Writing

Quail’s SQL Editor includes AI assistance to help you write queries more efficiently.

Getting Query Suggestions

1

Describe What You Want

Click the AI Assistant button or press Ctrl/Cmd + K to open the AI prompt.
2

Ask in Natural Language

Describe what you want to query in plain English:
  • “Show me the top 10 customers by revenue”
  • “Get average order value by month for the last year”
  • “Find all customers who haven’t ordered in 90 days”
3

Review Generated SQL

The AI will generate SQL based on your request and show you the query before executing it.
4

Execute or Modify

You can either:
  • Click Run to execute the generated query
  • Click Insert to add it to your editor for modification
  • Click Regenerate if you want a different approach

Explaining Queries

Don’t understand a complex query? The AI can explain it:
  1. Select the query (or part of it) in the editor
  2. Right-click and choose Explain Query
  3. The AI will provide a plain-English explanation of what the query does

Visualizing Query Results

Turn your query results into charts directly from the SQL Editor:
1

Execute Your Query

Run a query that returns data suitable for visualization (typically aggregated data).
2

Switch to Visualize Tab

Click the Visualize tab in the results panel.
3

Choose Chart Type

Select a chart type that suits your data:
  • Bar Chart: Compare values across categories
  • Line Chart: Show trends over time
  • Pie Chart: Display proportions and percentages
  • Scatter Plot: Show relationships between variables
4

Configure Chart

Map your query columns to chart axes:
  • X-Axis: Usually your dimension or category
  • Y-Axis: Your measure or metric
  • Series: For grouped data (optional)
5

Apply Formatting

Customize your chart:
  • Colors and themes
  • Axis labels and titles
  • Legend position
  • Number formatting

Saving Charts

Once you’ve created a visualization you like:
1

Click Save Chart

Click the Save Chart button above the visualization.
2

Add Details

Provide:
  • Chart name: Descriptive name for the chart
  • Description: What the chart shows (optional)
  • Tags: For organization and searchability
3

Choose Destination

Select where to save your chart:
  • Save as new chart: Creates a standalone chart
  • Add to dashboard: Adds directly to an existing dashboard
4

Confirm

Click Save to store your chart.
Saved charts remember both the query and visualization configuration, making them easy to refresh with updated data.

Query History

Quail automatically saves your query history:
  • Access previous queries from the History panel on the right
  • Click any historical query to load it into the editor
  • Star frequently used queries for quick access
  • Search your history by query text or date

Keyboard Shortcuts

Speed up your workflow with these keyboard shortcuts:

Execute Query

Ctrl/Cmd + EnterRun the current query

AI Assistant

Ctrl/Cmd + KOpen AI query assistant

Format Query

Ctrl/Cmd + Shift + FAuto-format your SQL for readability

Comment Lines

Ctrl/Cmd + /Toggle comment on selected lines

Find & Replace

Ctrl/Cmd + FSearch within your query

New Tab

Ctrl/Cmd + TOpen a new editor tab

Working with Multiple Queries

Query Tabs

Open multiple queries simultaneously using tabs:
  • Click the + button to create a new tab
  • Each tab can use a different database connection
  • Switch between tabs with Ctrl/Cmd + 1-9
  • Close tabs with the X or Ctrl/Cmd + W

Saving Query Sessions

Save a collection of related queries:
  1. Open all the queries you want to save in different tabs
  2. Click Save Session in the top menu
  3. Give your session a name
  4. Later, load the session to restore all queries

Best Practices

Query Performance

  • Use LIMIT: Always limit results when exploring large tables
  • Be Specific: Select only the columns you need instead of using SELECT *
  • Add Indexes: Consider asking your DBA to add indexes for frequently queried columns
  • Use WHERE Clauses: Filter data at the database level rather than after fetching

Query Organization

  • Add Comments: Document complex logic with SQL comments
-- Calculate 30-day active users
SELECT COUNT(DISTINCT user_id) 
FROM events 
WHERE event_date >= CURRENT_DATE - INTERVAL '30 days';
  • Format Consistently: Use the auto-formatter for consistent, readable SQL
  • Save Reusable Queries: Star queries you use frequently
  • Use Descriptive Names: When saving queries, use clear names that indicate their purpose

Security

Never include sensitive data like passwords or API keys in your queries. Use parameters or environment variables instead.
  • Use read-only database connections when possible
  • Be cautious with UPDATE, DELETE, and DROP statements
  • Test queries on sample data before running on production databases
  • Review generated AI queries before executing them

Build docs developers (and LLMs) love