Skip to content

Query editor

  • PostgreSQL
  • MySQL
  • MariaDB

A query tab is where you write and run SQL against one connection. The editor is Monaco, with your dialect’s highlighting, inline syntax errors, autocomplete and signature help. You can run the whole script, the statement at the cursor, or a selection. Each tab has its own session on the server, so its transaction, USE and search_path stay with it.

Querybara's query editor connected to the Larchwood PostgreSQL database. The side bar shows the shop schema's tables (customers, inventory, order_items, orders, products, reviews, shipments, suppliers). The editor holds a formatted 16-line query with a CTE that sums monthly revenue by product category over shop.orders, order_items and products, and the result grid below lists 54 rows of month, category, orders, units, revenue, avg_order and share_pct.Querybara's query editor connected to the Larchwood PostgreSQL database. The side bar shows the shop schema's tables (customers, inventory, order_items, orders, products, reviews, shipments, suppliers). The editor holds a formatted 16-line query with a CTE that sums monthly revenue by product category over shop.orders, order_items and products, and the result grid below lists 54 rows of month, category, orders, units, revenue, avg_order and share_pct.
Write SQL with a real editor and get every row back in a fast grid.
  1. Double-click a MySQL, MariaDB or PostgreSQL connection in the sidebar to connect it.
  2. Choose New query (the plus button) in the title bar, or press Ctrl + T (Cmd + T on macOS). You can also right-click the connection, or use its Actions button, and choose New query tab.

New query and Ctrl + T open the tab on the connection of the tab you are in, or on an open connection when that tab has none. The command palette (Ctrl + Shift + P) runs the same command as Query: New Query Tab; see Command palette.

The footer of the tab shows the connection, the server version and the connection status.

Action Toolbar Keys
Run the selection, or the statement at the cursor Run Ctrl + Enter
Run every statement Run all Ctrl + Shift + Enter
Format the SQL Format Shift + Alt + F
Show the plan Explain Ctrl + E
Run and measure the plan Explain Analyze Ctrl + Shift + E

On macOS, Cmd takes the place of Ctrl in every shortcut above.

  • Statement at the cursor. When the cursor sits after a statement (on its delimiter, a trailing comment or the blank lines after it), that statement runs. Before the first statement, the first one runs.
  • Selection. The selected text is split into statements and each one runs in order.
  • Run all. Every statement in the tab runs in order. A failed statement stops the script.

Statements run one at a time. Each statement’s messages, row counts and timings go to the Messages tab. An error is marked in the editor at the position the server reports, and a click on the message brings you back to it.

The plan views are described in Visual explain. To build the statement at the cursor visually, choose Open in query builder (see Visual query builder).

Life of a queryA SQL statement travels from the query tab through the statement splitter and the safety check to the connection host process, through an optional SSH tunnel to the database; result rows stream back from the host directly to the results grid, bypassing the main process.Query tabeditorSplitter; · DELIMITER · $$Safety checkwrite rulesConnection hostone process eachSSH tunnelwhen the profile has onePostgreSQLlarchwoodMain processnot on the row pathResults grid1,000 rowsConfirm: productionselect … from shop.ordersSQLstmtstmtstmtstmt#10421 Oak dining tablecancelcancel

Life of a query

  1. You run all of the editor, the statement at the cursor, or the selection.
  2. The splitter cuts the text into statements. It understands DELIMITER, dollar quoting and nested comments, so a function body stays whole.
  3. Each statement passes the safety check: a risky write, or any write on a production profile, waits for you to confirm it.
  4. The statement goes to the connection’s own host process, then through the profile’s SSH tunnel if it has one, to the server.
  5. Rows stream from the host straight to the page, 1,000 at a time, into the results grid. They never pass through the main process.
  6. Cancel asks the server itself to stop the statement, and the session stays usable.

The splitter cuts a script on ; and understands:

  • the MySQL and MariaDB DELIMITER command, the way the mysql client reads it: the first word of a line, between statements
  • PostgreSQL dollar quoting ($$ … $$ and $tag$ … $tag$) and SQL-standard function bodies (BEGIN ATOMIC … END)
  • nested comments, which PostgreSQL allows, and strings
  • MySQL executable comments such as /*!40101 … */, which count as statements
DELIMITER //
CREATE PROCEDURE shop.order_total(IN p_order INT)
BEGIN
SELECT SUM(quantity * unit_price) FROM shop.order_items WHERE order_id = p_order;
END //
DELIMITER ;

Statements that hold only comments and whitespace are skipped.

Write placeholders instead of literal values, and Querybara asks for the values before it runs.

Placeholder Example Engines
:name WHERE customer_id = :customer PostgreSQL, MySQL, MariaDB
$1, $2 WHERE customer_id = $1 PostgreSQL, MySQL, MariaDB
? WHERE customer_id = ? MySQL, MariaDB (on PostgreSQL ? is a jsonb operator)
  1. Write the statement with placeholders:

    SELECT id, ordered_at, total
    FROM shop.orders
    WHERE customer_id = :customer AND total > :min_total;
  2. Run it. The Parameter values dialog lists each placeholder.

  3. Type a value for each one, or tick NULL.

  4. Choose Run.

Values are sent as bound parameters, never pasted into the SQL. A named parameter used in several statements is asked for once. Placeholders inside strings, comments, quoted identifiers and dollar-quoted bodies are ignored, as are PostgreSQL ::type casts and MySQL @variables. One statement cannot mix placeholder styles.

Before anything runs, every statement is checked. If any statement needs a confirmation, the dialog lists each one with its reasons, and nothing runs until you choose Run anyway. Cancel stops the whole run.

These statements always ask, on every connection:

  • UPDATE or DELETE without a WHERE clause
  • DROP of an object, and ALTER … DROP COLUMN or DROP PARTITION
  • TRUNCATE
  • EXPLAIN ANALYZE of a statement that writes, because it executes the statement

A connection marked as production in its profile asks before every write: the dialog is titled Run on a production connection? The Confirm every write option in the connection profile does the same for any connection. A profile marked Read-only refuses a script that contains a write, and nothing in it runs.

Choose Cancel in the toolbar. Querybara asks the server to stop the statement over a separate control connection (KILL QUERY on MySQL and MariaDB, pg_cancel_backend on PostgreSQL). If the server has not stopped it after a few seconds, Querybara stops reading the result. The Messages tab reports Query cancelled, and the tab’s session stays usable.

Each query tab starts in auto-commit mode: every statement is committed as it runs.

  1. Clear Auto-commit in the toolbar.
  2. Run your statements. The next run starts a transaction, and the toolbar shows Transaction open.
  3. Choose Commit to keep the changes, or Rollback to undo them.

A BEGIN or START TRANSACTION you run yourself also shows Transaction open. Turning Auto-commit back on while a transaction is open asks whether to commit it first. Closing a tab with an open transaction, with its close button or Ctrl + W, asks first; Roll back and close rolls the changes back.

Every statement you run is recorded with its connection, time, duration, row count and status (succeeded, failed or cancelled).

  1. Choose History in the title bar, or press Ctrl + Shift + H (Cmd + Shift + H on macOS).
  2. Type in Search statements to filter the list. Tick Only the active tab’s connection to narrow it to one connection.
  3. Hover an entry and choose Open to put its text in a new query tab.

Querybara saves the text of every query tab, its cursor position and its connection a couple of seconds after each change. Results and passwords are never saved.

  • After a crash, the tabs come back when you start Querybara again, with the banner “Querybara closed unexpectedly. This tab was restored from its autosave”.
  • After a normal quit, open tabs also come back, marked as restored from the last session.
  • A restored tab does not connect or run anything by itself. Choose Dismiss to hide the banner.
  • Closing a tab on purpose discards its saved text.

MongoDB consoles and shells and the Redis CLI are saved and restored the same way.

When the connection drops, a banner across the tab shows the error. Choose Reconnect to open the connection again; the tab opens a new session on the next run.

On macOS, use Cmd for Ctrl in these keys. They work anywhere in the window while no dialog is open, and you can change them in Keyboard Shortcuts. The editor’s own keys, in the table above, stay as they are. See Keyboard shortcuts.

Action Keys
New query tab Ctrl + T
Close the tab Ctrl + W
Show or hide history Ctrl + Shift + H
Command palette Ctrl + Shift + P
Keyboard Shortcuts editor Ctrl + K, then Ctrl + S

querybara query runs SQL from -e, a file or stdin with the same splitter, the same parameter styles and the same confirmations. Statements that need confirmation ask in a terminal, or need --yes.

Terminal window
querybara query postgres://[email protected]/shop \
-e "select id, total from shop.orders where customer_id = :customer" \
--param customer=1042
Terminal window
querybara query postgres://[email protected]/shop -f migrate.sql --continue --error-log errors.log

See querybara query for every flag.

Documents Querybara 0.1.1 · built frombc9f5aa