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

# SQL Editor

pgconsole's SQL editor is a workspace for writing queries, browsing schemas, and working with results. What sets it apart:

* **Understands your SQL** — syntax highlighting, autocomplete, formatting, error detection, and function signature help are all backed by a PostgreSQL parser, not regex.
* **Guardrails** — [database access control](/features/database-access-control) and [audit logs](/features/audit-log) ensure every query is authorized and recorded.
* **AI assistant** — generate, explain, fix, and rewrite SQL with an [AI assistant](/features/ai-assistant) that understands your schema context.

<img src="https://mintcdn.com/pgconsole/4pgorsNxQziP7MhU/images/features/sql-editor/sql-editor-overview.webp?fit=max&auto=format&n=4pgorsNxQziP7MhU&q=85&s=3dfd69226a9e3a6c445280addcf086d7" alt="SQL Editor overview" width="2880" height="1800" data-path="images/features/sql-editor/sql-editor-overview.webp" />

## Editor

### SQL Intelligence

The editor parses your SQL in real-time to provide:

* **Autocomplete** — context-aware suggestions for tables, columns, joins, and CTEs (`Ctrl+Space`)
  <img src="https://mintcdn.com/pgconsole/nLaHd7UibVdUgRMb/images/features/sql-editor/sql-editor-autocomplete.webp?fit=max&auto=format&n=nLaHd7UibVdUgRMb&q=85&s=b1c549dbb195be458ef656db45194ebc" alt="Autocomplete suggestions" width="1600" height="1200" data-path="images/features/sql-editor/sql-editor-autocomplete.webp" />
* **Formatting** — pretty-print or collapse to one line
  <img src="https://mintcdn.com/pgconsole/rbW70_vWDOmu0xN8/images/features/sql-editor/sql-editor-format.webp?fit=max&auto=format&n=rbW70_vWDOmu0xN8&q=85&s=32c5bc9297c3debd0a23fa58fa9dd33c" alt="SQL formatting" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-format.webp" />
* **Error detection** — red underlines with hover tooltips; optionally **Fix with AI**
* **Code folding** — collapse `SELECT`, `WITH`, and other blocks

### Quick SQL Generation

When a table or view is selected in the schema browser, the Quick SQL menu generates SQL templates and inserts them into the editor:

<Note>INSERT, UPDATE, DELETE, CREATE TABLE, and ALTER ADD COLUMN are only available for tables (not views).</Note>

<img src="https://mintcdn.com/pgconsole/rbW70_vWDOmu0xN8/images/features/sql-editor/sql-editor-quick-sql.webp?fit=max&auto=format&n=rbW70_vWDOmu0xN8&q=85&s=18684b6634ada4c067c8cb9d952afcda" alt="Quick SQL menu" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-quick-sql.webp" />

## Data Grid

Query results appear in the panel below the editor in a virtual-scrolling grid that handles large result sets efficiently.

<img src="https://mintcdn.com/pgconsole/rbW70_vWDOmu0xN8/images/features/sql-editor/sql-editor-results.webp?fit=max&auto=format&n=rbW70_vWDOmu0xN8&q=85&s=738ea3d1cec019f950271eb5e61cb996" alt="Query results" width="868" height="347" data-path="images/features/sql-editor/sql-editor-results.webp" />

### Navigation

| Action              | Behavior                      |
| ------------------- | ----------------------------- |
| Click a row         | Open the row detail panel     |
| Double-click a cell | Start editing that cell       |
| `j` / `↓`           | Select next row               |
| `k` / `↑`           | Select previous row           |
| `Space`             | Pin or unpin the selected row |

Pinned rows stick to the top of the grid for easy comparison across large result sets.

### Inline Editing

With `write` permission, you can modify data directly in the grid. All changes are staged locally — nothing is committed until you explicitly execute.

<img src="https://mintcdn.com/pgconsole/kVdxVj076wk77F1r/images/features/sql-editor/sql-editor-row-detail.webp?fit=max&auto=format&n=kVdxVj076wk77F1r&q=85&s=42ffbad8542a88c8727001f5fa1a2ad2" alt="Row detail panel" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-row-detail.webp" />

| Action          | How                                                                         |
| --------------- | --------------------------------------------------------------------------- |
| Edit a cell     | Double-click the cell, or click the row and press Edit in the detail panel  |
| Add a row       | Click the **+** button in the results toolbar                               |
| Delete a row    | Right-click and select Delete, or use the Delete button in the detail panel |
| Duplicate a row | Right-click and select Duplicate (primary key fields cleared)               |

Staged changes are color-coded: green for new rows (INSERT), amber for modified rows (UPDATE), red with strikethrough for deleted rows (DELETE).

When changes are pending, a floating bar lets you **Preview** the generated SQL or **Discard** all changes. The preview modal shows syntax-highlighted INSERT/UPDATE/DELETE statements and optionally an AI-powered risk assessment before you **Execute All**.

<img src="https://mintcdn.com/pgconsole/kVdxVj076wk77F1r/images/features/sql-editor/sql-editor-staged-changes.webp?fit=max&auto=format&n=kVdxVj076wk77F1r&q=85&s=457102868e4f25ca9e67f6c48aba0202" alt="Staged changes preview" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-staged-changes.webp" />

### Data Export

* **Export results** — downloads visible rows as CSV, TSV, JSON, or Markdown (requires `export` permission)
* **Copy as Markdown** — copies results as a markdown table to the clipboard

## Schema Inspection

Schema tabs provide detailed inspection of database objects.

<img src="https://mintcdn.com/pgconsole/rbW70_vWDOmu0xN8/images/features/sql-editor/sql-editor-schema-tab.webp?fit=max&auto=format&n=rbW70_vWDOmu0xN8&q=85&s=159bcc5cd42fd89910372ddb0489bf90" alt="Schema tab" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-schema-tab.webp" />

## Active Sessions

The Processes button in the toolbar opens a modal showing active database connections. The list auto-refreshes periodically. With `admin` permission, a **Terminate** button appears on each row with a confirmation countdown.

<img src="https://mintcdn.com/pgconsole/rbW70_vWDOmu0xN8/images/features/sql-editor/sql-editor-processes.webp?fit=max&auto=format&n=rbW70_vWDOmu0xN8&q=85&s=8d98e65c7124ba6cf560960d53f6968a" alt="Active processes" width="1440" height="900" data-path="images/features/sql-editor/sql-editor-processes.webp" />
