> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tablepro.app/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL editor

> Run statements and scripts, read several result sets, write with completion, snippets, multiple cursors and Vim mode, and share queries as links in TablePro for Linux

`Ctrl+T` opens an editor tab on the window's connection. In a window with no tab open, **Open SQL Editor** does the same.

![SQL editor joining products and categories, with Coffee, Accessories, Tea, and Brewing result rows](https://mintcdn.com/ngquct/0mXJ_FWPFa4tFQSo/images/linux-sql-editor.png?fit=max\&auto=format\&n=0mXJ_FWPFa4tFQSo\&q=85\&s=29732fa3e3a886f79c0cc8de8facc921)

Group stock by category and inspect the query results

## Run

| Keys | Runs |
| - | - |
| `Ctrl+Enter` | The selection, or the whole text as a script |
| `Ctrl+Shift+Enter` | The statement at the cursor |
| `Escape`, or **Stop** | Stops the running query on the server |

A script is split the way its engine reads it, `DELIMITER` on MySQL and `GO` on SQL Server included, and sent one statement at a time, or one batch at a time on SQL Server. A failed statement stops the script, except on SQL Server, where the next batch runs.

Stopping cancels the statement on the server. Cassandra and ScyllaDB have no cancel, so the app stops waiting and the server runs the statement to its own timeout.

The editor gives up on a query after 60 seconds. Change that under **Preferences > Editor > Query timeout (seconds)**, or per connection with **Custom Query Timeout** in its [Options](https://docs.tablepro.app/linux/connect.md#options). 0 turns the timeout off.

## Results

Each result set, row count, notice and error of a run is its own entry in the results list. A result keeps 10,000 rows and a run 100,000 rows or 256 MB, whichever comes first; past that a banner offers **Export All…**, which runs the statement again on a separate read-only connection and writes every row to a file. After a failed statement, **Go to Error** puts the cursor where the server places the error.

A statement that opens a transaction leaves **Commit** and **Roll Back** in the results pane until you pick one. Closing the window asks first while the transaction is open.

## Edit query results

Editing requires a single SELECT from one base table, its whole primary key in the result, and columns the driver can trace to that table. Joins and grouped results stay read-only. Open the table from the sidebar when its query result cannot be edited. Review pending edits, then click **Save** in the results pane to write them or **Discard** to drop them.

## Completion and snippets

Completion offers tables, views, columns, schemas, functions and keywords, and resolves aliases. Type a snippet's trigger, pick it in the list, then press `Tab` to move between its stops and `Shift+Tab` to go back.

| Trigger | Writes |
| - | - |
| `sel` | `SELECT … FROM … WHERE` |
| `ins` | `INSERT INTO … VALUES` |
| `upd` | `UPDATE … SET … WHERE`, and `ALTER TABLE … UPDATE … WHERE` on ClickHouse |
| `del` | `DELETE FROM … WHERE` |
| `selj` | `SELECT … JOIN … ON`, except on Cassandra and ScyllaDB |
| `ctab` | `CREATE TABLE` with an `id` key column |
| `cidx` | `CREATE INDEX` |

Your own snippets are saved queries with a keyword. In **Saved Queries**, click the menu button on a query's row and choose **Set Keyword…**, then type the keyword in the editor and pick it in the list. A query saved against a connection expands in that connection's editors, and one for all connections in every editor, on any engine. A keyword with a built-in's trigger replaces the built-in.

```sql theme={null}
SELECT COUNT(*) FROM ${1:table_name} WHERE ${2:condition};
```

Fields, choices and the `;;` cursor marker work as in [Favorites](https://docs.tablepro.app/features/favorites.md#fields), with one difference: `${1|ASC,DESC|}` starts at its first choice, with no menu.

The snippets folder of earlier builds, `~/.local/share/tablepro/snippets`, is copied into saved queries for all connections on the first launch after the update. Each snippet keeps its trigger as its keyword unless another saved query already uses that keyword or it is an SQL word such as `select`. The files stay in the folder.

## Files and drafts

`Ctrl+O` opens a `.sql` file into the tab, and so does dropping one on the editor. `Ctrl+S` saves back to it and `Ctrl+Shift+S` saves to another file.

The text of every editor tab is kept as you type. A connection's tabs, editor tabs with their text and table tabs with their page and sort, reopen when the connection opens.

## Multiple cursors

| Keys | Does |
| - | - |
| `Ctrl+D` | Selects the word at the cursor, then adds a cursor at its next match |
| `Ctrl+Shift+L` | Adds a cursor at every match of the selection or the word |
| `Shift+Alt+Up`, `Shift+Alt+Down` | Adds a cursor on the line above or under the cursor, in the same column |
| `Ctrl+click` | Adds a cursor, or removes the one you click |
| `Escape` | Returns to one cursor, keeping its selection |

Typing, deleting, pasting and moving work at every cursor, and one `Ctrl+Z` takes the edit back at all of them. A click, a find, **Format** or `Page Up` returns to one cursor.

## Vim mode

Turn on **Preferences > Editor > Vim Keybindings**. The line under the text shows the mode and the command you are typing, and the editor's own `Ctrl` shortcuts keep working in every mode. Every other key goes to Vim, `Escape` too, so use **Stop** to stop a running query.

| Command | Does |
| - | - |
| `:w` | Saves the tab's file, asking for one when the tab has none |
| `:e` | Reads the tab's file again, asking first when that loses changes |
| `:q` | Closes the tab, asking first about unsaved changes or an open transaction |
| `:wq`, `:x` | Saves, then closes the tab |

## Redis and MongoDB

On a Redis connection the editor takes Redis commands, one per line, and shows each reply as `redis-cli` does. On MongoDB it takes mongosh statements such as `db.orders.find()`, `aggregate`, `runCommand`, `use` and `show`, and shows one document per row.

## History and saved queries

`Ctrl+Shift+H` opens **Query History**: every run from the editor, with full-text search, filters by connection, time and status, and export as SQL or CSV. A run that can carry a password is left out.

**Save Query…** in the editor's menu keeps the text against the connection. **Saved Queries** in the main menu lists them, the window's connection first and the queries for all connections under **All Connections**. A query's menu sets its keyword with **Set Keyword…**.

## Share a query or result

Sign in to your TablePro account first, under **Preferences > Account > Sign In** or with **Sign In…** in the share dialog.

| To share | Do this |
| - | - |
| The selection, or the whole text when nothing is selected | **Share Query…** in the editor's menu |
| The result shown | **Share Result…** in the editor's menu, or right-click a result grid and choose **Share Result…**, under **Export…** |
| A table's rows, with its filter and sort | Right-click the table tab's grid and choose **Share Result…** |
| A saved query | Click **Favorites** at the top of the sidebar, right-click the query and choose **Share…** |

A table shares from its first row, whichever page is on screen. With a seat on a team, **Share As** in the dialog picks **Personal** or the team. For a result, **Columns** offers **Keep**, **Mask as** each mask, or **Remove** for every column, and columns that look sensitive start masked. **Manage Shared Links…** in the main menu opens your links in the browser.

The dialog, the Free and Pro limits, and what a link sends are in [Shared Links](https://docs.tablepro.app/features/shared-links.md#the-share-sheet). The column choices are in [Sensitive data](https://docs.tablepro.app/features/shared-links.md#sensitive-data). Opening a `tablepro://share` link puts its SQL in a new editor tab without running it, and asks for a connection when the window has none.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.