Query tabs

A query tab is an editor with its own session on one database.

A query tab
Editor, results bar, result grid, tab status row.

Opening a query tab

The parts of a query tab

PartContent
File barOnly when the tab has a file: its path, * while unsaved.
EditorSee SQL editor and autocomplete.
Results barMessages (n), then one label per result set: 1: 12 rows, 2: 1,000+ rows.
Tab status rowConnection, role and database (local · postgres@adventureworks), transaction status, PL/pgSQL, state of the run; right: cursor position.
KeyAction
Alt+Down / Alt+UpEditor ↔ results.
Ctrl+RHide / show the results pane.
Alt+Shift+Up / Alt+Shift+DownResults pane smaller / larger (mouse: drag the line above the results bar).
F6Object tree ↔ tab.

Executing: F5

F5 (Query → Execute) sends the selection, or the whole text when nothing is selected. Rows are displayed as they arrive; the UI is not blocked.

Scripts: several statements at once

The text is sent unchanged as one simple-query message, as pgAdmin does; pgtc does not split it. Values come back in text format. Without transaction control of its own, the message is one implicit transaction block:

Each statement with a row description is a result set; each completed statement leaves its command tag in Messages. A run keeps its newest 10,000 messages: when there are more, the first line says how many earlier ones were dropped; errors are never dropped.

Results

Several result sets
Three SELECTs, three result sets.
KeyAction
Ctrl+PgDn / Ctrl+PgUp (Alt+PgDn / Alt+PgUp)Next / previous result set — also from the editor.
Alt+MResult set ↔ Messages — also from the editor.
Alt+Right / Alt+LeftIn the results: cycle through all labels, Messages included.

After a run the first result set is shown; a run without one ends on Messages. A SELECT of zero rows is a result set (empty grid with column names).

The grid

KeyAction
Arrows, PgUp / PgDnMove the cell cursor.
Home / EndFirst / last column.
Ctrl+Home / Ctrl+EndFirst / last loaded row.
Ctrl+C / Ctrl+InsertCopy the cell — the complete value, also when shown truncated.
Ctrl+A, Ctrl+CCopy the loaded rows: tab-separated, with a header row.
Alt+EndFetch all rows.
F2Context menu: Export result…, Fetch all.

Large results: 1,000 rows at a time

A paused result
A paused result: 1,000+ rows.

pgtc reads 1,000 rows (the batch; a setting) and then stops reading from the connection: socket backpressure, no cursor, no transaction needed. The backend stays in the statement, blocked sending rows.

A paused result is a statement still executing on the server: it holds its snapshot and locks until all rows are fetched, it is cancelled (Alt+Shift+C), the next statement runs in the tab, or the tab closes.

While a result is paused the session is busy: autocomplete reads no new names, and F7 templates and the generate commands of F4 are refused.

Closing a paused result — on the next execute, Commit or Rollback:

Messages

Messages after a script
One command tag per statement, then the total time.
LineMeaning
UPDATE 2, SELECT 13, …Command tag of each completed statement.
NOTICE:, WARNING:, INFO:Notice messages (per client_min_messages), shown while the statement executes.
ERROR:With DETAIL, HINT and the position in the editor text.
BEGIN, ROLLBACKSent by pgtc for the tab's transaction switches (Transactions).
NOTIFY: channel "name" (pid 1234): payloadA notification on a channel the session LISTENs on; shown on delivery, also between runs.
Total time: 21 msElapsed time of the run, measured by pgtc; time a paused result waited for Fetch more is not counted.
KeyAction
Enter / double clickOn an error or notice with a known position: jump to that line in the editor.
Ctrl+CCopy the message under the cursor (all its lines).
Ctrl+A, Ctrl+CCopy all messages.
F2Context menu.

Errors

An error in Messages
Line and ^ position of an undefined column.

Errors raised inside a DO block or in PL/pgSQL mode carry no position in the sent text: pgtc takes the line from CONTEXT (PL/pgSQL function inline_code_block line N …) and, for a failing SQL statement inside the block, the column from the internal query and internal position. Positions are those at the time of the error; after edits a jump may be off.

Cancelling a query

Alt+Shift+C (Query → Cancel) sends a cancel request for the tab's backend over a separate connection. It also ends a paused result and stops a running export.

If the run has not ended after 5 seconds (a setting), pgtc asks The server did not react to the cancel request. Close this query tab's session? Close session drops this tab's session (an open transaction is lost); the tab keeps its text and the next F5 opens a new session. Keep waiting waits on.

Transactions

Two switches per tab, in the Query menu; a new tab takes them from Settings.

SwitchDefaultOnOff
Auto commitonpgtc sends no transaction control (the server's autocommit, as in psql).Before a run, if the transaction status is idle, pgtc sends BEGIN. The block stays open until Query → Commit / Rollback.
Auto rollback on erroroffAfter a failed run that leaves a block open, pgtc sends ROLLBACK.The block stays aborted until rolled back.
An open transaction
Auto commit off: the BEGIN pgtc sent, the tab marked (tx).

pgtc shows the transaction status the server reports after every request — however the block was opened (a BEGIN typed in the editor counts too):

Tab labelStatus rowTransaction status
(tx)Transaction openIn a transaction block.
Transaction aborted – ROLLBACK neededIn a failed transaction block.

Commit, Rollback and the two switches have no default key; bind them in keymap.toml, or execute COMMIT; / ROLLBACK; from the editor. The dashboard lists a tab left on (tx) as idle in transaction.

PL/pgSQL mode

Ctrl+P (Query → PL/pgSQL mode) toggles the mode per tab: the editor text is the body of an anonymous code block, sent as DO $pgc$ … $pgc$;. If the text has no BEGIN … END, pgtc adds it.

PL/pgSQL mode
RAISE NOTICE output in Messages.

Closing a query tab and quitting

Ctrl+W, a click on the tab's ×, or View → Close tab ends the tab's session; a statement still executing is cancelled.

Good to know