Database
The SQL workspace
Data → SQL in a project is a workspace for writing and running SQL: several queries open in tabs, queries you keep, and a panel underneath for results, messages, history and query plans.
Everything on SQL and migrations still holds: a statement runs inside this project only, as the project's own confined database role; it cannot reach another project or the platform's own tables; and every run is written on the project's audit record with your name. A read-only member of the company cannot run SQL.
Tabs
- New tab: the plus at the end of the row.
- Rename: double-click the tab, or press
F2with the tab focused. - Reorder: drag a tab.
- Close: the cross, the middle mouse button, or
Deletewith the tab focused. The clock button reopens the last closed tab (the newest 10 are kept). - Tabs and their text are kept in your browser, per project. They are not sent to the server until you run or save.
The editor
- SQL is coloured as you type: keywords, strings, numbers, comments and function calls.
- Completion: after two letters it offers this project's tables and columns, keywords and common functions. After
table.it offers that table's columns. Arrow keys choose;ReturnorTabaccepts;Escapedismisses. Tabindents andShift Taboutdents the selected lines.Returnkeeps the current indent.- Format lays the query out with capitals for keywords and one main clause per line. With text selected it formats only the selection.
- To leave the editor with the keyboard, press
Escapeand thenTab.
| Keys | What it does |
|---|---|
Cmd Return / Ctrl Return | Run the tab, or only the selected text |
Cmd S / Ctrl S | Save the query |
Cmd Shift F / Ctrl Shift F | Format |
Running
Run sends the whole tab. If text is selected, only the selection is sent.
A run is read-only unless you agree otherwise, each time:
- A statement that writes (for example
insert,update,create table) asks for confirmation before it runs. - A statement that drops or empties something, or an
updateordeletewith nowhere, gets a stronger warning. - If a statement was not recognised as a write and the database refuses it as read-only, Messages offers "Run with changes allowed".
A statement is stopped after 30 seconds. A table you create starts with row-level security on and no rule, so it is closed to your application until you add one: see Row-level security and policies.
The output panel
Drag the bar above it to resize it, or focus the bar and use the up and down arrow keys.
- Results. The rows, up to the first 1,000. Click a column heading to sort (again to reverse, a third time to clear). Click a cell to select it; Copy cell and Copy row (as JSON) act on the selection, and double-clicking a cell copies it. CSV and JSON download what is shown. When several statements return rows, a chooser picks which result to show.
- Messages. What each statement did and how long it took, notices the database raised, and errors. An error shows its line and column, is underlined in the editor, and comes with the database's hint when it has one.
- History. Your own runs in this project, newest first: when, result, time taken, rows, and the statement, with Open (in a new tab) and Run again. Only you see your history; the newest 200 are kept, and Clear removes them. The audit record is separate and permanent.
- Plan. Plan shows how the database would carry out the statement without running it. Plan with timings runs it and shows where the time went; it is offered for read-only statements only. Select one statement first if the tab holds several.
Saved queries
Save (Cmd S) keeps the query in the open tab under a name. Saved queries are listed at the left; the Saved button shows or hides the list.
- A saved query is private unless you tick "Share with everyone who can open this project". A shared query is listed for everyone in the company, marked with its author's name.
- Only its author can change, rename, share, unshare or delete a saved query. Others can open it in a tab of their own or copy its SQL.
- Mark your own queries as favourites to list them first.
- A dot on a tab means its text differs from the saved version; save again to update it.
- You can keep up to 200 saved queries in a project. One query can be up to 200,000 characters.
The quick SQL panel
For a look at the data without leaving the page you are on, press SQL in the top bar, or Cmd E (Ctrl E on Windows and Linux). A small editor opens in a panel on the right of the page. It is the same editor as the workspace: highlighting, completion from your tables, formatting, and Cmd Enter to run everything or just the selected text.
- Results shows the rows in a compact grid with the count and the time taken; the first 200 are shown. Double-click a cell to copy it.
- Messages shows what each statement did, notices, and errors. The place of an error is underlined in the editor.
- History lists the last 15 runs from this panel; pick one to put it back in the editor.
- Open in SQL workspace carries the text into a new tab of the workspace, for sorting, export and query plans. Save keeps it as a saved query.
The panel keeps its text while you move between the pages of a project, and each project has its own. It uses the same door as the workspace: statements run as the project's own confined database role, runs are read-only unless you agree to a change each time, and every statement is recorded with your name. A read-only member cannot run statements here either.
The panel shares its place with the console assistant: the two buttons at its top switch between them. Where the assistant proposes SQL, Run in SQL panel or Try in SQL panel loads it here, and an error here has Explain this error.