Skip to main content
Cmd+Enter sends one statement: the one the cursor is in. Semicolons separate statements, so a single tab holds a whole script and you run it a piece at a time.
SQL Editor

SQL Editor with syntax highlighting

Run your first query

1

Open a query tab

Press Cmd+T, or choose File > New Tab.
2

Check the database picker

The toolbar picker binds this tab to one database. Changing it later affects this tab only.
3

Type a statement

Suggestions arrive as you type: tables after FROM and JOIN, a table’s columns after its alias and a dot. See Autocomplete.
4

Press `Cmd+Enter`

The statement under the cursor runs. Rows land in the grid below, under a tab named after the table they came from. See Query Results.
Instead of hardcoding a value, write :name and fill it in when the query runs. See Query Parameters. Cmd+O opens a .sql, .psql or .pgsql file as a query tab that Cmd+S writes back to. See SQL Files.

Running several statements

To run the whole tab, press Cmd+Shift+Enter, choose Execute All Statements from the Execute button’s menu, or use Query > Execute All Statements. Nothing needs to be selected first. Select text and Cmd+Enter runs the selection instead. A batch runs top to bottom:
  • On engines with transactions, the batch runs inside one. A failure stops it and rolls back everything before it. Engines without transactions run each statement as-is, with nothing to roll back.
  • The error names its place in the run: “Statement 3/5 failed: …”.
  • Each statement gets its own result tab, and each is recorded separately in query history.

Statement markers

The editor marks which statement it is about to send.
  • The statement holding the cursor gets a faint band behind it. It is a decoration, not a selection, so your next keystroke does not replace it.
  • Move the pointer over the gutter and a run button appears beside every statement. Click one to run that statement while the cursor is elsewhere. Their column is reserved at all times, so revealing them never shifts the text.
  • A run button takes the same safe mode checks and parameter prompts as any other run, and dims while a query is running.
  • VoiceOver reads each button as a button naming the line its statement starts on.
  • A BEGIN … END body counts as one statement, so a trigger or stored procedure gets one button rather than one per line inside it. BEGIN; and BEGIN TRANSACTION; are statements of their own.
Turn either marker off in Settings > Editor with Highlight current statement and Run button beside each statement.
Statement run controls in the editor gutter

A run control beside each statement, and a band over the one at the cursor

Moving between statements

Ctrl+Cmd+Left and Ctrl+Cmd+Right step to the previous and next statement. From part-way through a statement, the first press back lands on that statement’s own start. Neither wraps. Ctrl+Cmd+Enter runs the statement the cursor is in and then moves to the next one, so a script can be worked through without reaching for the pointer. The cursor moves first, so the next statement is visible while the current one runs. Option+Shift+Up and Option+Shift+Down extend the selection by a statement, the way macOS extends a selection by a paragraph. A statement hidden inside a collapsed fold unfolds when the cursor lands on it. All three commands are in the Query menu and rebindable in Settings > Keyboard.

Inline diagnostics

A structural mistake is underlined in red 500ms after you stop typing, and the underline clears as soon as you fix it. Only two things are reported, both of them problems more typing cannot fix: A half-written statement is never flagged. An opener you have not closed yet, a string you are still typing, and brackets inside a string or a comment are all left alone. Documents over 100,000 characters are not checked at all. On MongoDB connections the query parser runs as well, so an unknown collection method or a query that does not start with db. is underlined with the reason. Where the parser names the method, the method name itself is what gets marked.

Per-tab database picker

The editor toolbar carries a database picker, or a schema picker depending on the engine. Each tab binds to its own database, and switching the active database elsewhere leaves existing tabs on theirs. The picker lists what the sidebar lists, so it follows the sidebar’s database filter. PostgreSQL, Redshift and CockroachDB reconnect the session to change database, so their picker shows a lock instead of a menu. The tab keeps the database it opened with, and a tab bound to anything other than the connection’s active database runs on a separate connection. See Cross-Database Tabs.

Find and replace

Press Cmd+F to open the find panel, Cmd+G and Cmd+Shift+G to walk the matches. Switch the panel to Replace mode to replace the current match or all of them. Match modes are contains, matches word, starts with, ends with, and regular expression, each with match case and wrap around toggles. The editor also carries multiple cursors, for editing several places at once.

Formatting

Press Cmd+Shift+L to format the statement at the cursor. The toolbar’s format button and Query > Format Query do the same, and the shortcut is rebindable in Settings > Keyboard. The token-based formatter breaks a line per clause, indents two spaces, uppercases keywords, and keeps your comments, string literals, cursor position and dialect identifier quoting (MySQL backticks, PostgreSQL double quotes). JOINs, subqueries, CASE expressions, recursive CTEs, window functions and set operations are all handled. Procedural blocks pass through with minimal changes: PL/pgSQL DO, stored procedures, T-SQL BEGIN/END. Before:
After:

AI assistance

Explain with AI (Cmd+L) explains the query at the cursor and Optimize with AI (Cmd+Option+L) suggests improvements. When a query fails, Fix with AI in the error banner rewrites it. Inline suggestions complete your SQL as ghost text: Tab accepts, Escape dismisses. See AI Assistant for setup. For the execution plan rather than an opinion, press Cmd+Option+E and see Explain Visualization.

Editor settings

Settings > Editor holds line numbers, current-line and current-statement highlighting, word wrap, code folding, the per-statement run button, tab width, auto-uppercase keywords, query parameters, and vim mode. Editor font family and size are per theme, in Settings > Appearance. Editor windows remember their size, position and font zoom between launches. See Query Tabs.