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
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.
Writing SQL Queries
Basic Query Structure
Start with a simple SELECT query to explore your data: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:- Table Names
- Column Names
- SQL Keywords
- Functions
Start typing a table name and press Tab to auto-complete. The editor shows matching tables from your schema.
Running Queries
Execute
Click the Run button or use the keyboard shortcut:
- Windows/Linux:
Ctrl + Enter - Mac:
Cmd + Enter
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
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”
Review Generated SQL
The AI will generate SQL based on your request and show you the query before executing it.
Explaining Queries
Don’t understand a complex query? The AI can explain it:- Select the query (or part of it) in the editor
- Right-click and choose Explain Query
- 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:Execute Your Query
Run a query that returns data suitable for visualization (typically aggregated data).
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
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)
Saving Charts
Once you’ve created a visualization you like:Add Details
Provide:
- Chart name: Descriptive name for the chart
- Description: What the chart shows (optional)
- Tags: For organization and searchability
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
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:- Open all the queries you want to save in different tabs
- Click Save Session in the top menu
- Give your session a name
- 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
- 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
- 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
