Skip to content

Query and edit data

A query console is a SQL file bound to one connection. You run a statement or the whole script, the results open in the Services tool window, and rows of a single table can be edited there and written back in one transaction. Console, result grid and data editing: Works.

A saved connection: Connect to a database.

  1. In the Database tool window, select the connection (or any table under it).
  2. Click SQL (New Query Console) in the toolbar, or right-click and choose New › Query Console. Tools › Database › New Console does the same from the menu bar.

The console opens as console.sql (then console_2.sql and so on), kept in .ferris-idea/consoles/<connection id>/, and starts in the connection’s default schema, for example public on PostgreSQL. The bar above the editor shows the connection and schema, the run and cancel buttons, the transaction mode and History.

Any other .sql file of the project can run against a connection too. The first time you run one, a popup asks for the connection, with one of the matching dialect preselected; the choice is kept in .ferris-idea/sql-files.toml. Tools › Database › Choose Data Source changes it.

  1. Put the caret in a statement, or select the text you want to run.
  2. Press ⌘↩ (CtrlEnter) or click ▶.
  • A selection runs as it is; a script of one statement runs that statement.
  • With several statements and no selection, a popup asks: “Statement at caret: …” (preselected) or “Whole script (N statements)”. Esc runs nothing.
  • A comment line directly above a statement belongs to it. Inside a CREATE FUNCTION or CREATE PROCEDURE body, the whole CREATE is offered, not the inner statement.
  • The script is split by the dialect’s own rules: DELIMITER in MySQL and MariaDB, dollar quotes and E'' strings in PostgreSQL, BEGIN … END bodies, GO batches in SQL Server.
  • After each statement a grey note at its last line says how it went: “12 ms · 3 rows”, “1 row affected”, or “failed” in red.

A failed statement stops the run. The Output tab lists the error with its SQLSTATE and, where the database names one, the position (“at column 8”); the statements after it are listed as not run. PostgreSQL notices (RAISE NOTICE) appear under their statement in Output.

An UPDATE or DELETE without a WHERE clause asks before it runs, with the number of rows it would touch, for example “Delete all 42 rows of stock?”. The choices are Run, Run, don’t ask again for shop in this session (with your connection’s name) and Cancel (preselected). Tools › Database › Ask Again for Unsafe Changes turns the question back on.

Click ■ (Cancel Running Statement). PostgreSQL gets a cancel request, MySQL and MariaDB a KILL QUERY on a second connection, SQLite an interrupt. SQL Server, Oracle and DuckDB cannot be cancelled yet; the button stays grey for them.

The Tx button of the console bar switches the mode:

  • Tx: Auto commits every statement. This is the default unless the connection’s Auto-commit option is off.
  • Tx: Manual keeps one session open. The first statement starts a transaction, the button shows the number of statements, and Commit and Rollback appear. Typing COMMIT or ROLLBACK ends the transaction too, and the console stays in manual mode.

Switching back to Auto, or closing the window, with a transaction open rolls it back and says so. Nothing is ever committed without you asking.

The first run opens the Services tool window (⌘8, Alt8). It has an Output tab and one Result tab per result set, so a script with three SELECTs gives Result 1 to Result 3.

  • Pages. 500 rows per page by default; the Page menu offers 10, 100, 250, 500, 1000 and All. The pager (⏮ ‹ › ⏭) and a label such as “1–500 of 1200” sit in the toolbar.
  • Sort. Click a column header: ascending, descending, original order. ⇧-click adds a second key; the headers show ▲1 and ▼2. Console results are sorted on the rows already loaded, without running the query again.
  • Filter. The Filter field keeps the rows with a cell that contains the text, ignoring case. The ⏷ mark in a header opens the column’s values with their counts, to tick the ones you want. Both filters combine; the label then says “2 rows (filtered from 4)”.
  • Views. Table, Tree and Text; Transpose shows one line per column, handy for wide rows. Record (⇧↩) opens a side panel with the current row, the full value of a cell and a summary.
  • Keep a result. A new run replaces the unpinned result tabs of the statements it runs. Pin a tab with 📌 (⌥⇧P) to keep it.

NULL shows as a dimmed <null>. Numbers are right-aligned. Columns size themselves up to 320 pixels; drag a header edge to change one, double-click it to fit.

A result can be edited when it comes from a plain SELECT on one table (no join, subquery, GROUP BY, DISTINCT, set operation or WITH), the table has a primary key or a unique index over NOT NULL columns, and every key column is in the result. Computed columns stay read-only.

  1. Double-click a cell, or press ↩ or F2. Type the new value and press ↩. Delete sets the cell to NULL. Changed cells are highlighted.
  2. Add a row with + Row (⌘N). Columns you leave empty show <default> and are left out of the INSERT.
  3. Mark a row for deletion with − Row (⌘⌫, CtrlDelete); it is struck through until you submit.
  4. Click Preview (⌥⇧⌘↩) to read the statements that will run.
  5. Click Submit (n) (⌘↩). All changes run in one transaction (deletes, then updates, then inserts) and the query runs again. Sort, filter, page and view stay as they were.

Revert (⌥⌘Z) drops every pending change.

Each UPDATE and DELETE matches the key and the values as they were loaded. If someone changed the row in the meantime, so that a change hits anything other than exactly one row, the whole batch is rolled back and the note names the row.

Double-click a table in the Database tool window, or select it and press F4 (Edit Data). The table opens in a Services tab of its own, read from the server page by page:

  • WHERE and ORDER BY fields filter and sort on the server; ↩ runs the query again. Clicking a header edits the ORDER BY. Text that would end the statement or comment out the rest is refused.
  • 500 rows per page; the total comes from COUNT(*). Without an ORDER BY the table’s key gives the order, so pages stay stable.
  • Views and tables without a key open read-only.
  • Tx: Auto ▾ chooses the transaction mode and the isolation level. In manual mode each Submit is kept behind a savepoint until Commit (n) or Rollback.
  • The grid does not let you edit: the result is not a plain single-table SELECT, the table has no key, or a key column is missing from the select list. Add the key column, or open the table with Edit Data.
  • Submit says a row was changed by someone else: reload (run the query again), then edit again.
  • ■ stays grey: the system cannot be cancelled yet (SQL Server, Oracle, DuckDB). Set a Query timeout on PostgreSQL, MySQL or MariaDB connections instead.
  • Nothing happens on ⌘↩ in a new .sql file: the data source popup is open and waits for a connection.
Keyboard of
ActionShortcut
BrowseConsole.History.Browse⌥⌘ECtrlAltE
Services⌘8Alt8
Tools › Database › New Console⇧⌘F10CtrlShiftF10
Tools › HTTP Client › Send Request at Caret⌘↩CtrlEnter

The grid’s own keys (Submit, Revert, + Row, − Row, Preview, Pin, Record) are named above; they are not in the keymap and cannot be changed.

An agent runs SQL with run_sql. Statements that only read run at once in a read-only session; anything that could change data or schema is previewed until the call says apply: true, and each statement needs the permission of its kind on that connection. edit_table_data edits rows by key the same way. Details: Let an agent use a database.

  • cancel_sqlchangessshdatabase-permissiontrusted-projectCancel the run_sql call that is running on a connection: PostgreSQL's cancel request, MySQL/MariaDB KILL QUERY, SQLite interrupt.
  • edit_table_datachangesdry run by defaultsshdatabase-permissiontrusted-projectEdit rows of a table: update cells, insert and delete rows.
  • read_table_datareadssshdatabase-permissiontrusted-projectRead one page of a table like the table data editor: optional where and order_by clause bodies (refused when they contain ; or a comment), page (0-based, 500 rows).
  • run_sqlchangesdry run by defaultsshdatabase-permissiontrusted-projectRun SQL on a workspace connection.
  • split_sql_statementsreadsSplit an SQL script into statements with byte ranges, using the lexical rules of the dialect.
  • sql_consolechangessshwritedatabase-permissiontrusted-projectCreate a new SQL console for a connection (a file under .ferris-idea/consoles/<connection id>/ bound to it, starting in the data source's default schema); returns its path and schema (needs the read-schema permission).
  • sql_file_data_sourcechangeswritetrusted-projectReport or set the connection a .sql file runs against: consoles belong to their connection, other files can be bound (kept in .ferris-idea/sql-files.toml).