> ## 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

> Write and run SQL with syntax highlighting, multi-statement execution, find and replace, and a built-in formatter

`Cmd+Enter` sends one statement: the one the cursor is in. Semicolons separate statements, so a single tab holds a whole script and you run it a piece at a time.

![SQL Editor](https://mintcdn.com/ngquct/sezpSJY0oLylJ5LP/images/sql-editor.png?fit=max\&auto=format\&n=sezpSJY0oLylJ5LP\&q=85\&s=219c0325db8b175c78aaa4424946b67f)

SQL Editor with syntax highlighting

## Run your first query

**1. Open a query tab**

Press `Cmd+T`, or choose **File > New Tab**.

**2. Check the database picker**

The toolbar picker binds this tab to one database. Changing it later affects this tab only.

**3. Type a statement**

Suggestions arrive as you type: tables after FROM and JOIN, a table's columns after its alias and a dot. See [Autocomplete](https://docs.tablepro.app/features/autocomplete.md).

**4. Press `Cmd+Enter`**

The statement under the cursor runs. Rows land in the grid below, under a tab named after the table they came from. See [Query Results](https://docs.tablepro.app/features/query-results.md).

Instead of hardcoding a value, write `:name` and fill it in when the query runs. See [Query Parameters](https://docs.tablepro.app/features/query-parameters.md).

`Cmd+O` opens a `.sql`, `.psql` or `.pgsql` file as a query tab that `Cmd+S` writes back to. See [SQL Files](https://docs.tablepro.app/features/sql-files.md).

## Running several statements

To run the whole tab, press `Cmd+Shift+Enter`, choose **Run All Statements** from the **Run** button's menu, or use **Query > Execute All Statements**. Nothing needs to be selected first. Select text and `Cmd+Enter` runs the selection instead.

A batch runs top to bottom and stops at the first statement that fails. The error names its place in the run: "Statement 3/5 failed: …". Each statement is recorded separately in [query history](https://docs.tablepro.app/features/query-history.md).

Each statement that returns rows gets its own result. Statements that return none, such as `INSERT`, `UPDATE` or `CREATE TABLE`, share one result once there are two or more: it is named after how many there were, adds up their rows affected and time, and shows their server output in order. It sits where the last of them ran, so the result of the last statement is the one on screen. A run keeps the last 100 results that return rows. When it leaves older ones out, each result it keeps says how many there were in all.

A SQL Server script runs a batch at a time instead, cut at its `GO` lines, so a `DECLARE`d variable reaches every statement after it. See [Scripts and batches](https://docs.tablepro.app/databases/mssql.md#scripts-and-batches).

### Which transaction the batch runs in

| The batch | Runs in | A failure or Stop |
| - | - | - |
| Ordinary statements | A transaction TablePro opens and commits | Everything rolls back |
| Ordinary statements, with [Manual Commit](#manual-commit) on | A transaction TablePro opens and leaves open for you to commit | Everything rolls back |
| One that manages its own: `BEGIN`, `START TRANSACTION`, `XA START`, `SET autocommit`, `SAVEPOINT` on SQLite, `SET TRANSACTION` on Oracle, `BT` on Teradata | The script's own transaction | The transaction it left open is rolled back |
| One holding a [statement a transaction cannot hold](#statements-a-transaction-cannot-hold) | No transaction | Each statement that ran stays applied, and the banner counts them |
| A script on SQL Server | No transaction, unless the script opens one with `BEGIN TRAN` | What ran stays applied, and a transaction the script left open is reported |
| Anything, on a connection that already has a transaction open | That transaction | The transaction stays open and the message says so |

The last row wins over the rest. The open transaction comes from a `BEGIN` you ran with `Cmd+Enter`, a write under Manual Commit, a `SET autocommit = 0`, `LOCK TABLES` on MySQL or MariaDB, a `SET TRANSACTION`, `SAVEPOINT` or `LOCK TABLE` on Oracle, or an [MCP client's](https://docs.tablepro.app/developers/mcp-tools.md) `begin`, and a batch that joins it sends no `BEGIN`, `COMMIT` or `ROLLBACK` at all: the script's own text decides, so a script ending in `COMMIT` commits. Where a failed statement has left the transaction unable to commit, the message says to roll it back rather than offering the choice. A `BEGIN` left running here reaches the rest of the window too, so a grid save and a **Users & Roles** apply land inside it.

PostgreSQL, Redshift, CockroachDB, MySQL, MariaDB, TiDB, SQLite, DuckDB, SQL Server and Oracle report what their session holds. Anywhere else there is no answer to be had, so a plain batch is wrapped as it always was and a self-managed script is left alone after a failure, since the transaction its text opened may well predate the run.

Two things survive a rollback in any of those cases. MySQL, MariaDB and Oracle commit a `CREATE`, `ALTER` or `DROP` the moment it runs, along with everything before it, and CockroachDB commits the open transaction before it processes any DDL at all.

### Statements a transaction cannot hold

One of these anywhere in the batch leaves the whole of it unwrapped. The engine either refuses the statement inside a block, as PostgreSQL refuses `VACUUM`, or applies it and quietly throws it away, as SQLite does with `PRAGMA foreign_keys`.

| Engine | Statements |
| - | - |
| PostgreSQL, Redshift, CockroachDB | `VACUUM`, `CREATE INDEX CONCURRENTLY`, `REINDEX SCHEMA`, `ALTER SYSTEM`, `CREATE DATABASE`, `DISCARD ALL`, `ALTER TYPE … ADD VALUE` |
| MySQL, MariaDB, TiDB, OceanBase | `SET TRANSACTION`, `SET sql_log_bin`, `SET binlog_format`, `SET GLOBAL gtid_mode`, `STOP REPLICA` |
| SQLite, libSQL | `VACUUM`, `DETACH`, `PRAGMA journal_mode`, `PRAGMA foreign_keys`, `PRAGMA wal_checkpoint` |
| DuckDB | `CHECKPOINT`, `FORCE CHECKPOINT`, `DETACH` |
| SQL Server | `CREATE`, `ALTER` and `DROP DATABASE`, `BACKUP`, `RESTORE`, `RECONFIGURE` |

The MySQL row covers the preamble a `mysqldump` or `mariadb-dump` file carries, so a dump pasted into the editor runs the way `mysql` runs it. CockroachDB adds `SET CLUSTER SETTING`, `BACKUP`, `RESTORE` and `IMPORT`, and Redshift adds `CREATE EXTERNAL TABLE`, `CREATE LIBRARY` and `ALTER TABLE … APPEND`.

A `CLUSTER` or `REINDEX` naming one table, and a `CALL` of a procedure that commits inside itself, depend on the object rather than on the text, so the batch around them keeps its transaction. Run those on their own.

Redis has no transaction TablePro can open, so every command runs and answers as sent. A `MULTI` in the script opens a block of its own: each command after it answers `QUEUED` until `EXEC`, and a batch that fails or is stopped inside the block discards it. See [Redis](https://docs.tablepro.app/databases/redis.md).

### Stopping a batch

Stop (`Cmd+.`) acts between statements. The run halts before the next one goes out, and a transaction TablePro or the script opened is rolled back. A batch running outside a transaction keeps what it already wrote, and the statements that ran keep their results and their query history entries.

The commit is the point of no return. While it is on the wire Stop is dimmed and says why, and nothing else reaches it either: closing the tab releases the tab and nothing more, and disconnecting queues behind the commit, so the server finishes it either way. A script's own `COMMIT` counts the same, and the statements after it become stoppable again.

If the connection dies while the commit is in flight, the result says the statements may or may not be saved and query history records them the same way. There is nothing left to ask, so no rollback is sent. Check the table before running them again.

### Each tab runs its own queries

Stop and `Cmd+.` act on the tab you are looking at. A query started in another tab, or on the same connection in another window, waits for the running one rather than stopping it: the waiting tab shows the ordinary **Executing…** spinner and a live Stop for as long as the other one runs, and a table opened in a new tab shows an empty grid with a spinner. Stopping the waiting tab leaves the running batch alone.

## Transactions

### The open transaction bar

While a session holds a transaction, a bar above every tab of the connection says **Transaction Open**, names the database, and offers **Roll Back** and **Commit**. It shows whoever opened the transaction: a `BEGIN` you ran, a write under [Manual Commit](#manual-commit), a grid save inside one, or an [MCP client's](https://docs.tablepro.app/developers/mcp-tools.md) `transaction_control`. It goes once the transaction ends, by its buttons, by a typed `COMMIT` or `ROLLBACK`, or with the session. On PostgreSQL, Redshift and CockroachDB each database keeps its own connection, so two databases with open transactions show a row each. The [connections strip](https://docs.tablepro.app/features/workspace-rail.md) marks the entry with an hourglass, so you see it from another connection.

**Database > Commit Transaction** and **Database > Roll Back Transaction** do what the buttons do, for the database of the tab in front. Neither has a shortcut until you record one in **Settings > Keyboard**.

**Transaction Failed** means a statement inside it failed and it can no longer commit, so only **Roll Back** is offered. On PostgreSQL any failed statement does this, reads included: a typo in a filter leaves nothing to commit. **Roll Back** asks first at every [Safe Mode](https://docs.tablepro.app/features/safe-mode.md) level. **Commit** asks what a typed `COMMIT` asks: nothing at **Silent**, a confirmation at the Alert levels, a confirmation and Touch ID at the Safe Mode levels. At **Read-Only** it is hidden, and **Commit Transaction** is dimmed.

Commit and Roll Back act on the connection the bar names. When other work ran there after you clicked, they do nothing and say so: check the transaction and try again.

The server rolls back what a session leaves open, so closing, disconnecting, quitting and relaunching to update ask first while a transaction is open, with **Commit** as the default. See [Open transactions](https://docs.tablepro.app/features/connection-window.md#open-transactions).

### Manual Commit

With **Manual Commit** on, nothing you change is saved until you commit it. A new connection starts with it off. Turn it on in the connection editor's [**Safe Mode**](https://docs.tablepro.app/connections/connection-form.md#safe-mode) pane, or choose **Database > Manual Commit** while connected: both change the one setting saved with the connection.

MySQL, MariaDB, TiDB, OceanBase, Oracle, ClickHouse, Redshift and CockroachDB commit schema and maintenance statements on their own, so Manual Commit is not offered there. The toggle and the menu item are dimmed, with "This database commits schema and maintenance statements on its own, so changes can't wait for Commit." under them, and a connection saved with Manual Commit on runs as if it were off.

The first write opens a transaction and the bar appears. Writes after it join that transaction until you commit or roll back, and reads open nothing. That covers statements you run in a query tab, grid saves, [Data Rewind](https://docs.tablepro.app/features/change-tracking.md#restoring-a-save) restores, imports, and what an MCP client writes through [`execute_query`](https://docs.tablepro.app/developers/mcp-tools#execute_query) or `insert_rows`. Structure changes, **Users & Roles**, **Copy To…**, [Generate Rows](https://docs.tablepro.app/features/table-operations.md#generate-test-rows) and [Shortcuts](https://docs.tablepro.app/integrations/shortcuts.md) actions still save at once. A statement that manages its own transaction, such as `BEGIN` or `SET autocommit`, runs as typed, and so does a [statement a transaction cannot hold](#statements-a-transaction-cannot-hold) on its own.

If that first write fails, the transaction it opened is rolled back. Turning Manual Commit off leaves an open transaction open, bar and all, until you commit or roll it back.

A change Manual Commit cannot hold is refused before anything runs, with a message that says how to run it:

* a write on a connection with no transactions, one that cannot report whether a transaction is open, or one holding locks with no transaction open
* a run that mixes a change with a statement a transaction cannot hold, such as `VACUUM`
* a save that sets session options around its statements, as putting back rows with their identity values does on SQL Server
* an import that turns off foreign key checks, as **Disable foreign key checks** does by default, or runs with **Wrap in transaction** off or **On error** set to **Skip and Continue**

Of the other engines, the ones that report what their session holds are named under [Which transaction the batch runs in](#which-transaction-the-batch-runs-in). Once a connection has shown it cannot report, **Database > Manual Commit** is dimmed while it is off, with "This database can't report an open transaction, so it commits each change." under it. While it is on, the item stays available to turn it off.

### Schema changes while a transaction is open

A Structure save, a new table and a trigger change each run on a connection of their own. While a transaction is open on the connection, whether Manual Commit or a `BEGIN` you typed opened it, they ask **A Transaction Is Open** first: the change can wait on that transaction's locks until you commit or roll back. **Continue** runs it, and **Cancel** runs nothing.

## Statement markers

The editor marks which statement it is about to send.

* The statement holding the cursor gets a faint band behind it. It is a decoration, not a selection, so your next keystroke does not replace it.
* Move the pointer over the gutter and a run button appears beside every statement. Click one to run that statement while the cursor is elsewhere. Their column is reserved at all times, so revealing them never shifts the text.
* A run button takes the same [safe mode](https://docs.tablepro.app/features/safe-mode.md) checks and [parameter](https://docs.tablepro.app/features/query-parameters.md) prompts as any other run, and dims while a query is running.
* VoiceOver reads each button as a button naming the line its statement starts on.
* A `BEGIN … END` body counts as one statement, so a trigger or stored procedure gets one button rather than one per line inside it. `BEGIN;` and `BEGIN TRANSACTION;` are statements of their own. On Oracle, a whole [PL/SQL block or unit](https://docs.tablepro.app/databases/oracle.md#pl%2Fsql) is one statement.
* On SQL Server an `IF` stays one statement through its `ELSE`, even when a `;` ends the `IF`'s branch: `IF @a = 1 SELECT 1; ELSE SELECT 2;`.
* On MySQL and MariaDB a `DELIMITER //` line runs nothing, and `//` then ends a statement, as the `mysql` client reads a script. The line counts only as the first thing on its line, before any statement text. A `;` still ends a statement outside a routine body.
* On MySQL and MariaDB a routine whose body is an `IF … END IF`, `WHILE … END WHILE`, `LOOP … END LOOP` or `REPEAT … END REPEAT` is one statement too, with or without a `DELIMITER` line.
* On PostgreSQL the rows after `COPY ... FROM STDIN`, up to the line holding only `\.`, belong to the `COPY` and never run as SQL. Running the `COPY` sends them to the server as its data, as `psql` does, without the `\.` line. **Stop** ends the `COPY` at once with none of its rows loaded; inside a transaction you opened, the transaction is left failed until you roll it back. On Redshift and PGlite, which cannot take rows this way, the `COPY` stops before anything is sent. The `\restrict` and `\unrestrict` lines `pg_dump` writes run nothing.

Turn either marker off in **Settings > Editor** with **Highlight current statement** and **Run button beside each statement**.

![Statement run controls in the editor gutter](https://mintcdn.com/ngquct/4sKIZ96FMUNZTuxL/images/sql-editor-statement-run.png?fit=max\&auto=format\&n=4sKIZ96FMUNZTuxL\&q=85\&s=eb34a76dc2be7ab02939036609983b2a)

A run control beside each statement, and a band over the one at the cursor

### Moving between statements

`Ctrl+Cmd+Left` and `Ctrl+Cmd+Right` step to the previous and next statement. From part-way through a statement, the first press back lands on that statement's own start. Neither wraps.

`Ctrl+Cmd+Enter` runs the statement the cursor is in and then moves to the next one, so a script can be worked through without reaching for the pointer. The cursor moves first, so the next statement is visible while the current one runs.

`Option+Shift+Up` and `Option+Shift+Down` extend the selection by a statement, the way macOS extends a selection by a paragraph.

A statement hidden inside a [collapsed fold](https://docs.tablepro.app/features/code-folding.md) unfolds when the cursor lands on it. All three commands are in the Query menu and rebindable in **Settings > Keyboard**.

## Selecting text

Double-click takes a word, triple-click takes a line, and holding the button after either keeps
extending at that size: a double-click drag moves whole words, a triple-click drag moves whole
lines. Drag back past where the gesture started and that first word or line stays whole.

`Shift`-click moves the far end of the selection and leaves the end you started from where it is, so
a `Shift`-click on the other side of the anchor turns the selection around instead of trimming it.
`Shift`-double-click and `Shift`-triple-click do the same to whole words and whole lines.

Operators select as one unit. Double-click the `=` in `WHERE id = 1` and the operator comes back;
`<=` and `||` come back whole.

Drag past the top or bottom edge and the editor scrolls to follow at a steady speed. Extending with
`Shift`+arrow follows the end that is moving, so the moving edge stays on screen no matter how far
the selection already runs.

The JSON viewer, a table's DDL and an import preview are read-only, and take the same arrow-key
movement and `Shift`+arrow selection as the editor here.

## Inline diagnostics

Problems more typing cannot fix are underlined 500ms after you stop typing, and the underline clears as soon as you fix it. A red underline marks a structural mistake:

| Underlined in red | Message |
| - | - |
| A closing bracket with no opener, or one closing the wrong kind | No matching opening bracket |
| A `/*` with no `*/` after it | Unterminated comment |

An orange underline marks a character that looks like SQL but reaches the server as something else. Chinese, Japanese and Korean input methods type these in full-width mode, and text pasted from a document or a chat often carries them. `SELECT 1；` looks like a complete statement, but `；` does not end it, so the editor and the server read it and the statement after it as one.

| Underlined in orange | Type instead |
| - | - |
| Full-width punctuation, such as `；` `，` `（` `）` `＝` | The ASCII character it resembles |
| Full-width letters and digits, such as `ＳＥＬＥＣＴ` or `１` | ASCII letters and digits |
| Curly quotes `‘` `’` `“` `”` | A straight `'` or `"` |
| A no-break space, an ideographic space, or a typographic space such as a thin space | An ordinary space |

Each message names the character and the ASCII character to type instead. **Query > Remove Invisible Characters** turns every flagged space into an ordinary one in a single step. Orange underlines appear on SQL connections only, and none of them stops a query from running.

Full-width letters and digits inside a name written in another script, such as `売上２０２４`, are not underlined. Full-width punctuation is, even inside a name: both parentheses in `价格（元）` are flagged. Write such a name as a quoted identifier and the underline goes.

Text between `'`, `"` or `` ` `` quotes and text in a `--` or `/* */` comment is not checked. Neither is a `#` comment on MySQL and MariaDB, a `$$` body on PostgreSQL, or a `[bracketed]` name on SQL Server and SQLite. On other engines, a `#` comment, a `$$` body or a bracketed name is checked like the rest of the query.

On Elasticsearch, Typesense and Weaviate the request body is checked and the request line is not, so the `/*` in `GET /_cat/indices/*` is a wildcard, not a comment. Redis and etcd commands are not checked, because a bracket in an argument is plain text.

A half-written statement is never flagged. An opener you have not closed yet, a string you are still typing, and brackets inside a string or a comment are all left alone. Documents over 100,000 characters are not checked at all.

Switching tabs or loading a query checks the new text the same way, without a keystroke. Rest the pointer on an underline to read its message. In VoiceOver, the rotor lists every underline under **Query Issues**, each read with its message.

On MongoDB connections the query parser runs as well, so an unknown collection method or a query that does not start with `db.` is underlined with the reason. Where the parser names the method, the method name itself is what gets marked.

## Per-tab database picker

The editor toolbar carries a database picker, or a schema picker depending on the engine. Each tab binds to its own database, and switching the active database elsewhere leaves existing tabs on theirs. The picker lists the databases the sidebar's database filter keeps, then the system databases after a divider.

PostgreSQL, Redshift and CockroachDB reconnect the session to change database, so their picker shows a lock instead of a menu. The tab keeps the database it opened with, and a tab bound to anything other than the connection's active database runs on a separate connection. See [Cross-Database Tabs](https://docs.tablepro.app/databases/postgresql.md#cross-database-tabs).

## Undo

Each query tab keeps its own undo history, so switching to another tab and back leaves `Cmd+Z` where it was. **Clear Query**, loading a query from history, and **Apply to Editor** each count as one edit that `Cmd+Z` takes back.

## Find and replace

Press `Cmd+F` to open the find panel, `Cmd+G` and `Cmd+Shift+G` to walk the matches. Switch the panel to Replace mode to replace the current match or all of them. Match modes are contains, matches word, starts with, ends with, and regular expression, each with match case and wrap around toggles.

Replace moves on to the next match. All replaces every match in one step, and one `Cmd+Z` undoes it. With a regular expression, `$1` in the replacement inserts the first capture group. A read-only editor offers find only.

The editor also carries multiple cursors, for editing several places at once.

## Earlier versions

A query tab keeps earlier versions of its text on this Mac. **File > Revert To** lists the last ten, each named by its time and, where one applies, what kept it: Run, Before Replace or Before Restore. Choose one to put it back in the tab. **Browse All Versions…** at the foot of that menu opens a History tab, the same view [saved queries](https://docs.tablepro.app/features/favorites.md#saved-query-versions) use: **Changes** compares a version with the tab's current text, and **Restore This Version** puts it back. A restore from either place first keeps the text it replaces, as a Before Restore version.

A version is kept:

* when the query runs
* after a pause in typing. Pauses within 5 minutes of the first one fold into one version, so steady typing leaves about one every 5 minutes
* before **Clear Query**, before a query loads into the tab from [Query History](https://docs.tablepro.app/features/query-history.md) or Open Quickly, before **Apply to Editor** from the [AI assistant](https://docs.tablepro.app/features/ai-assistant.md), and before a saved query is inserted

Each tab keeps up to 50 versions, for 30 days or for Query History's **Keep entries for** when that is shorter. Blank text and a copy of the newest version are skipped, and nothing is kept while [Query History is paused](https://docs.tablepro.app/features/query-history.md#pausing). Table tabs keep none.

Versions stay when a tab closes, and **File > Reopen Closed Tab** brings them back with it. Deleting the connection, or **Clear History…** in [Settings > Data > Query History](https://docs.tablepro.app/customization/data-settings.md#query-history), removes them. They never sync.

While the tab is on screen, `Cmd+Z` undoes **Clear Query**, a loaded query, **Apply to Editor** and an inserted saved query.

## Formatting

Press `Cmd+Shift+L` to format the statement at the cursor. The toolbar's format button and **Query > Format Query** do the same, and the shortcut is rebindable in **Settings > Keyboard**.

The formatter breaks a line per clause and keeps your comments, string literals, cursor position and each engine's quoted names: MySQL backticks, PostgreSQL double quotes, SQL Server brackets. A dollar-quoted body, such as a PL/pgSQL function or `DO` block, stays exactly as written. So does a line the client reads rather than the server: `GO` in a SQL Server script, `DELIMITER` in a MySQL one, a lone `/` in an Oracle one. A keyword or type name used as a column name, such as `date` in `SELECT date FROM events`, keeps the case you typed.

Indentation, case, and where lines break are set in **Settings > Editor > SQL Formatting**; see [SQL formatting](https://docs.tablepro.app/customization/editor-settings.md#sql-formatting). A `.sql-formatter.json` in a [linked SQL folder](https://docs.tablepro.app/features/favorites.md#linked-sql-folders) sets them for the files in that folder. JOINs, subqueries, CASE expressions, recursive CTEs, window functions and set operations are all handled. Stored procedures and T-SQL `BEGIN`/`END` blocks pass through with minimal changes. A query larger than 10.5 MB is not formatted: an error says so, and the text stays as it was.

**Before**:

```sql theme={null}
select u.id,u.name,count(o.id) as order_count from users u left join orders o on u.id=o.user_id where u.status='active' group by u.id,u.name having count(o.id)>5 order by order_count desc;
```

**After**, with the default rules:

```sql theme={null}
SELECT u.id,
       u.name,
       count(o.id) AS order_count
FROM users u
LEFT JOIN orders o
  ON u.id = o.user_id
WHERE u.status = 'active'
GROUP BY u.id, u.name
HAVING count(o.id) > 5
ORDER BY order_count DESC;
```

**After**, with a line width of 80, the join condition on the JOIN line and function case `UPPERCASE`:

```sql theme={null}
SELECT u.id, u.name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.status = 'active'
GROUP BY u.id, u.name
HAVING COUNT(o.id) > 5
ORDER BY order_count DESC;
```

In an Elasticsearch, Typesense or Weaviate console, formatting indents each JSON request body and leaves the request line as typed. A body that is not a single JSON value, such as a `_bulk` body or a GraphQL query, is left alone. Redis and etcd commands, SurrealQL and KafkaQL have no formatter, so Format is not offered there.

## Invisible characters

Characters that would otherwise draw as nothing, or as an ordinary space, are marked where they sit. A mark is the character itself: select it, arrow past it, or delete it like any other text.

![SQL editor with an orange BS box at the start of line 2, an outlined space on line 4 and a ZWSP box on line 5](https://mintcdn.com/ngquct/bYgoD4qhNfbZ4mKf/images/invisible-characters.png?fit=max\&auto=format\&n=bYgoD4qhNfbZ4mKf\&q=85\&s=addc96ec21c37054419de4b10949d4f3)

A backspace before SELECT, a non-breaking space before LIKE, a zero-width space after Composer

| Character | Shown as |
| - | - |
| Control characters, such as a backspace (U+0008) or NUL (U+0000) | A box with the character's short name: `BS`, `NUL`, `ESC` |
| Zero-width and formatting characters: zero-width space, byte order mark, soft hyphen, bidirectional controls | A box with the short name: `ZWSP`, `BOM`, `SHY`, `RLO` |
| Line and paragraph separators (U+2028, U+2029) | A box, `LSEP` or `PSEP`. The line continues past it, as it does for the database |
| Non-breaking, ideographic and other special spaces | An outline around the space |

Emoji sequences, variation selectors, and the joiners Arabic, Persian and Indic text rely on are left unmarked.

Control characters never arrive by typing. A stray backspace an input method sends, or a chord such as `Ctrl+Option+H`, is dropped. Pasted text is kept exactly as copied, with every invisible character marked.

Choose **Query > Remove Invisible Characters** to clean a query. With nothing selected, it removes marked characters outside string literals, quoted identifiers and comments. Special spaces, form feeds and vertical tabs become ordinary spaces, and a line or paragraph separator becomes a line break. Select text first to clean inside a literal as well. `Cmd+Z` undoes the whole change.

Invisible characters around a statement, such as a byte order mark in front of `SELECT` or a non-breaking space on the line after it, are not sent with it, and a line holding nothing else gets no run button. A NUL character inside a statement stops it from being sent. Remove the character and run it again.

A database often quotes the offending character back in its error message. Error messages show each marked character as its short name in angle brackets, so SQLite's reply to a stray backspace reads `unrecognized token: "<BS>"`. The error banner, query history and the other panes that show a database error also color the name orange and tint a special space. In an error alert, a special space shows as an ordinary space. The banner's copy button copies the database's text as it arrived, for a search or a bug report.

To hide the marks in the editor, turn off **Show invisible characters** in **Settings > Editor**. Read-only views, such as the AI assistant's code blocks, and error messages always show them. The data grid and the value fields have a switch of their own; see [Invisible characters](https://docs.tablepro.app/features/data-grid.md#invisible-characters).

## AI assistance

**Review** in the query bar sends the statement at the cursor, with the structure of the tables it names, for a review. Its menu holds **Explain with AI** (`Cmd+L`) and **Optimize with AI** (`Cmd+Option+L`), which send the same statement. When a query fails, **Fix with AI** in the error banner rewrites it. Inline suggestions complete your SQL as ghost text: `Tab` accepts, `Escape` dismisses. See [AI Assistant](https://docs.tablepro.app/features/ai-assistant.md#review-explain-optimize-and-fix) for what each action sends.

For the execution plan rather than an opinion, press `Cmd+Option+E` and see [Explain Visualization](https://docs.tablepro.app/features/explain-visualization.md).

## Editor settings

**Settings > Editor** holds line numbers, current-line and current-statement highlighting, word wrap, [code folding](https://docs.tablepro.app/features/code-folding.md), the per-statement run button, [invisible characters](#invisible-characters), tab width, [keyword case](https://docs.tablepro.app/features/autocomplete.md#keyword-case), [query parameters](https://docs.tablepro.app/features/query-parameters.md), and the [Vim](https://docs.tablepro.app/features/vim-mode.md) or [Emacs](https://docs.tablepro.app/features/emacs-mode.md) key bindings. Editor font family and size are on the same pane, and **SQL Formatting** at its bottom opens the [formatter rules](https://docs.tablepro.app/customization/editor-settings.md#sql-formatting).

The font size set by `Cmd+=` and `Cmd+-` is **Size** in [Editor settings](https://docs.tablepro.app/customization/editor-settings.md#font), so it is kept between launches. See [Query Tabs](https://docs.tablepro.app/features/tabs.md#switching-tabs).


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