Browsing to the SQL Editor
In the Toolbar, simply select SQL Lab and, in the drop-down menu, select SQL Editor.
Browse to and select different schema within the datasource, provided that Expose in SQL Lab is enabled in the database.
Multiple tabs for each query enable you to easily switch between different queries within one interface.
SQL Editor Panel
The SQL Editor panel allows different data source semantics / comments and runs one query at a time.
SQL Manager Bar
Enables you to manage your query work with common tools, such as run, save, share, and an auto-completion toggle. The Parameters button enables you to use the Jinja templating syntax to assign a set of parameters as JSON.
View the results of your queries here. Tools include:
- Explore: Open the table view chart with the run query.
- CSV: Save data in a CSV file.
- Clipboard: Copy data to your systen's clipboard.
Considerations when Running Queries
Some items to keep in mind when running queries in the SQL Editor:
- Even if the SQL Editor has several queries, only one query result will be showed (the last one);
- A query could timeout if it did not return values from the database (the default waiting time is 6 hours) or if the web server request timed out;
- Queries limit the number of rows that are retrieved from the database. This is because:
- It is an unnecessary overhead to bring in a lot of data from the database;
- Limiting the number of rows prevents long-running queries in the database; and,
- To avoid the accidental selection of Select * From with a table comprised of millions of rows, which could halt the database.
Create Table As (CTAS)
The CTAS button—found in the SQL Manager Bar—is used to materialize a query to a singular table in order to avoid complex joins or aggregations that can affect performance.
Access to this feature is controlled via the Edit Record tool when viewing a list of databases. Simply select the Allow CREATE TABLE AS checkbox to enable this feature. In addition, the CTAS Schema field enables you to create a new CTAS table in a specified schema.
Query History Tab
The Query History panel, as the name implies, shows a history of all previously run queries and conveys basic information, such as success/failure, start time, duration, progress (if still running), and so on.
Of particular note is the actions column, which enables you to do the following:
- Edit (pencil icon): Enables you to edit the query.
- New Tab (plus icon): Creates a new tab featuring the query.
- Trash Bin: Removes the query from the history log.