Skip to main content

SQL Lab

SQL Lab is the interactive SQL editor in a workspace. You pick one of the workspace's databases, write a query, run it, and look at the rows. When a query is worth keeping you can save it, keep pieces of it as snippets, or turn it into a virtual dataset that charts and dashboards can use.

SQL Lab with a query and its results

On the demo stack

The Docker demo stack has one connection, trino-demo, a Trino server with the catalogs tpch (generated TPC-H data in schemas tiny, sf1, sf100 and so on) and memory, plus Trino's own system. Every example on these pages runs against tpch.tiny.

SQL Lab is the first item in the Explore group of the sidebar, so it is the page a workspace opens on when the SQL Lab module is turned on. It runs on the database connections that a workspace admin has added under Manage → Workspace settings → Databases (see Connections). Trino and StarRocks connections are supported.

What is on the page​

The page is one resizable workspace. By default the editor takes 40 % of the height and the results below it 60 %, so at 1440×900 the grid shows about a dozen rows. Drag the grey bars between the panels to change their sizes.

AreaWhat it doesDetails
Tab strip (top)The page title SQL Lab, then one editor per tab, plus the + button and the ⌘ K for commands hint.The query editor
Explorer (left)Database picker, a search box and a tree of catalogs, schemas, tables and columns.The schema browser
Toolbar (above the editor)Run, Cancel, Format, Limit, the connection badge, a status badge, Save, Save as dataset, the command palette button and a … menu.The query editor
EditorThe SQL text, with syntax colouring and autocomplete. A Parameters bar appears when the SQL contains {{name}}.Query parameters
Results (below)The rows of the last run as a table or a small chart, with filter, copy and export.Query results
History, Saved, Snippets (tabs next to Results)Your past runs, the workspace's saved queries and reusable SQL fragments.History, saved queries and snippets

Run your first query​

  1. Go to Explore → SQL Lab.

  2. In the Explorer, choose a database from the picker at the top. If the workspace has exactly one database it is selected for you. The database name and engine appear as a badge in the toolbar, for example trino-demo · trino.

  3. Click in the editor and write a query. The editor opens with SELECT 1 in it:

    SELECT orderstatus,
    count(*) AS orders,
    round(sum(totalprice), 2) AS revenue
    FROM tpch.tiny.orders
    GROUP BY 1
    ORDER BY 3 DESC
    LIMIT 100
  4. Leave Limit at 1,000 rows or choose another value.

  5. Press Run (or ⌘ Enter on macOS, Ctrl Enter elsewhere).

While the query runs, a Running… badge shows in the toolbar and the Cancel button is enabled. When it ends the badge reads, for example, Done in 397 ms · 3 rows (or Failed in 125 ms), and the rows appear in Results.

Name tables completely

Trino tables are catalog.schema.table, for example tpch.tiny.orders. Click a table in the Explorer to insert its full name at the end of the editor text instead of typing it. Egret puts a space in front of it when it would otherwise run into the word before.

How the pieces fit together​

  1. Explore the schema in the Explorer, or open a table's preview.
  2. Write and run SQL in the editor. Use parameters for values that change between runs.
  3. Read the results; sort, filter, copy or export them.
  4. Keep what you need: save the query, store a snippet, or save it as a dataset.

Who the query runs as​

By default every query runs with the connection's own credentials, so all workspace members who can use SQL Lab see what that service identity can see. If the connection has per-user delegation switched on, the query runs as you, with a short-lived engine token minted from your session, and the engine's own access policies apply to you. A user who is not signed in through SSO cannot run on a delegated connection and gets a forbidden error. These options are set per connection; see Connections.

SQL Lab does not itself restrict the kind of statement you can send. A DROP TABLE on the demo Trino was sent to the engine and refused by the engine ("This connector does not support dropping tables"). What is allowed depends on the connection's credentials and on the engine's access policies.

Where your work is stored​

WhatWhereWho sees it
Open tabs (title, SQL, database, limit)Your browser's local storage, one set per workspaceOnly you, only in that browser
Query historyEgret, last 50 runs; Clear history hides your own entriesOnly you
Saved queriesEgret, in the workspaceWorkspace members with read access to saved queries
SnippetsEgret, in the workspaceWorkspace members with read access to saved queries
Result rowsEgret's object store, one file per runThe user who ran the query (and platform admins)

Because tabs live in the browser, clearing site data or switching browsers gives you a fresh Query 1. A tab's result and parameter values last only while the page is open: switching tabs keeps them, a reload does not. Anything you want to keep must be saved.

Pages in this section​

Limits and known issues​

  • SQL Lab needs at least one database connection granted to the workspace. Without one the database picker is empty, the Explorer says No connection is granted to this workspace. Ask a workspace admin., and Run reports Pick a connection.
  • The row limit, the 60-second query timeout and the 100,000-row ceiling are server settings; see Query results.

Further reading​