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

# SQL editor

> Write, run, and refine SQL queries in Mora's built-in editor.

The SQL editor is where you write and test queries for your datasets. It includes autocomplete, preview results, and integrates directly with the AI assistant.

## Editor layout

The dataset page is divided into panels:

* **Left panel**: the catalog browser. Expand schemas, tables, and columns from your datasource. Toggle with **Cmd+Left Arrow**.
* **Center panel**: the SQL editor where you write your query.
* **Bottom panel**: preview results from your most recent run. Toggle with **Cmd+J**.

## Writing a query

Start typing SQL and the editor will suggest table and column names from your datasource's [catalog](/datasources/catalog). The autocomplete is aware of your database dialect (PostgreSQL, Snowflake, BigQuery, etc.).

```sql theme={null}
SELECT
  date_trunc('month', created_at) AS month,
  COUNT(*) AS total_users
FROM users
GROUP BY month
ORDER BY month
```

## Running a preview

Press **Cmd+Enter** (or click the **Run** button) to execute your draft query and see results in the bottom panel. Previews run with a row limit and timeout to keep them fast.

The preview runs whatever is currently in the editor, you don't need to save first.

## Saving and publishing

Press **Cmd+S** to save. This:

1. Stores the query as the dataset's published query.
2. Triggers a background run that materializes the full results.
3. Updates any charts on dashboards that use this dataset.

## Keyboard shortcuts

| Action              | Shortcut         |
| ------------------- | ---------------- |
| Run query (preview) | `Cmd+Enter`      |
| Save dataset        | `Cmd+S`          |
| Toggle left panel   | `Cmd+Left Arrow` |
| Toggle bottom panel | `Cmd+J`          |
| Open AI chat        | `Cmd+/`          |

## Related

* [Draft and publish](/datasets/draft-suggest-publish), the query lifecycle.
* [AI SQL assistance](/ai/sql-errors), send errors to the AI.
* [Catalog](/datasources/catalog), how autocomplete knows your schema.
