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.
Before you start
Section titled “Before you start”A saved connection: Connect to a database.
Open a console
Section titled “Open a console”- In the Database tool window, select the connection (or any table under it).
- 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.
Run statements
Section titled “Run statements”- Put the caret in a statement, or select the text you want to run.
- 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 FUNCTIONorCREATE PROCEDUREbody, the wholeCREATEis offered, not the inner statement. - The script is split by the dialect’s own rules:
DELIMITERin MySQL and MariaDB, dollar quotes andE''strings in PostgreSQL,BEGIN … ENDbodies,GObatches 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.
Changes without WHERE ask first
Section titled “Changes without WHERE ask first”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.
Cancel a running statement
Section titled “Cancel a running statement”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.
Control transactions
Section titled “Control transactions”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
COMMITorROLLBACKends 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.
Read the results
Section titled “Read the results”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.
Edit rows in the grid
Section titled “Edit rows in the grid”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.
- Double-click a cell, or press ↩ or F2. Type the new value and press
↩. Delete sets the cell to
NULL. Changed cells are highlighted. - Add a row with + Row (⌘N). Columns you leave empty show
<default>and are left out of theINSERT. - Mark a row for deletion with − Row (⌘⌫, CtrlDelete); it is struck through until you submit.
- Click Preview (⌥⇧⌘↩) to read the statements that will run.
- 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.
Open a table’s data
Section titled “Open a table’s data”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 anORDER BYthe 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.
When it does not work
Section titled “When it does not work”- 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
.sqlfile: the data source popup is open and waits for a connection.
| Action | Shortcut |
|---|---|
| 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.
For agents
Section titled “For agents”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_sqlCancel the run_sql call that is running on a connection: PostgreSQL's cancel request, MySQL/MariaDB KILL QUERY, SQLite interrupt.edit_table_dataEdit rows of a table: update cells, insert and delete rows.read_table_dataRead one page of a table like the table data editor: optionalwhereandorder_byclause bodies (refused when they contain;or a comment),page(0-based, 500 rows).run_sqlRun SQL on a workspace connection.split_sql_statementsSplit an SQL script into statements with byte ranges, using the lexical rules of the dialect.sql_consoleCreate 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_sourceReport 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).
No tool matches. Try fewer words, or .