The SQL Editor is the central hub of Superset. You get here through the side bar Explore > SQL Editor, or by clicking Run in SQL Lab when viewing a Chart.
The SQL Editor consists of:
- Your Tabs: In-App Tabs for Queries.
- The Table Browser: Browse connected Databases.
- The Text Editor: SQL Editor.
- The Query Viewer: Multi-tab Query display.
Your Tabs
You may open as many Tabs as you like. By clicking the Arrow button to the right of a Tab Name you will have the option to rename or close a Tab, and to hide the Table Browser, allowing more space for the Text Editor and Query Viewer.
A new Tab can also be created clicking the blue plus (+) button in the the Query History.
The Table Browser
Browse your connected Databases and the Schemas, and Tables that it contains.
When a Table is opened, its columns and their types are displayed below.
You may change the order in which the columns are displayed, copy the SQL query used to obtain said columns, or close the preview.
The SQL Query created by the copy button includes all columns separately.
A Table opened here will automatically create a Preview Tab in the Query Viewer.
The Text Editor
The Text Editor is a typical SQL editor with JINJA support.
You may run your queries as usual and see the results displayed right below.
To create a new JINJA parameter click the Parameters button.
Parameters are defined as {"parameter"}: {"value"}
,
where {{ parameter }}
will resolve to value
, when used in a query.
There are pre-defined parameters that are available right away, such as:
{{ current_date }}
: Evaluates to today’s date.
{{ current_user }}
: Evaluates to username currently logged in to PM.
{{ current_user_id }}
: User ID currently logged in to PM.
{{ current_user_roles() }}
: Evaluates to Roles of the user currently logged in to PM.
Read more about JINJA templating here.
The Query Viewer
The Query Viewer itself consists of three parts, displayed as Tabs:
- The Result of your current Query, as run in the Text Editor,
- your Query History, and
- a Preview of full tables open in the Table Browser.
Results
The results tab displays your query as run in the text editor.
The Explore button takes you to the chart view in Superset,
the .CSV button initiates a download of the query,
the Clipboard button copies the query in JSON format.
Query History
View your recently run SQL queries, ordered chronologically.
The buttons to the right allow you to Edit your query, open it in a new Tab, or Delete.
Preview
The preview tab is created by the Table Browser. Whenever a Table is selected there, a table preview is created here. Closing the Column preview in the Table Browser also closes the preview.