Skip to the content
mantichora_/docs

Running statements

The console sends one statement at a time, the one under the cursor. It asks for the values a statement leaves open, keeps writes in a transaction when you want it to, and shows the plan a server would follow.

Running a statement

Ctrl+Enter (⌘Enter on a Mac), or Run on the toolbar, runs the statement under the cursor: not the selection and not the whole text. Statements are split on ; the way the connection’s own language does it, so a ; inside a string or a comment splits nothing.

  • A cursor on a ; belongs to the statement that ; ends.
  • A comment just above a statement belongs to it.
  • A cursor in the blank space after the last ; runs the last statement.

With the cursor on nothing that runs, the result says There was nothing to run.

Running everything

Run everything, in the Run menu and the command palette, sends every statement of the console in turn, each on its own and each with its own question if it is a risky one. It stops at the first that fails, with Stopped at statement N and the server’s reason. It has no key until you give it one.

Stopping one

While a statement runs, the toolbar shows Cancel; Ctrl+F2 does the same. On SQLite, DuckDB, SAP HANA and Arrow Flight SQL a stopped write throws its whole transaction away, so there the first press only warns, and the button turns into Cancel anyway.

Parameters

A name written as :name or {{name}} is a parameter: This statement is asking for values shows the statement with each name marked and a box for each, asked once however many times it is written. Names inside a string, a quoted name, a comment or PostgreSQL’s :: cast are left alone; ? and $1 are not parameters here.

Each value is written into the statement, quoted the way that server reads it. An empty box is an empty string, never a NULL: write is null in the statement for that. Run sends it, Do not run leaves it.

Transactions

While a session is open, the toolbar says How a statement lands: Autocommit or Manual commit. In manual commit a statement that writes opens a transaction first; the toolbar then says Transaction open with how long it has been, and shows Commit (Ctrl+Alt+K) and Roll back (Ctrl+Alt+R). Begin is in the Database menu and the palette.

New sessions commit as Settings → Connection → New sessions commit as says, autocommit unless changed; a production connection always opens in manual commit. A server with no transactions refuses manual commit and says so.

Plans

Explain on the toolbar, or Ctrl+Shift+P, asks the server how it would run the statement under the cursor, and runs nothing: the result’s Plan tab draws the answer as a tree of steps with their cost and the rows the server expects.

Analyse the statement, Ctrl+Alt+P, runs it to measure each step, and so asks first: Analysing runs this statement. Run it? Its tree adds the rows each step really gave, its time and its share of the whole.

PostgreSQL, MySQL, SQL Server, SQLite, Oracle, SAP HANA, ClickHouse, DuckDB and MongoDB explain; of them ClickHouse, SAP HANA, Oracle and SQLite do not analyse. A server that writes no plan, such as CockroachDB or TiDB, greys the command with the reason.