# SQL Editor

> A scratchpad for running SQL against any data source, with autocomplete, run selection and formatting. Save what works as a query.

Source: https://tini.so/docs/sql-editor

The **SQL Editor** is a scratchpad for running SQL against any of your data sources. Nothing is saved until you choose to save it, so it’s the place to try things out.

## Run SQL

1. Open **SQL Editor** in the sidebar and pick a data source.
2. Write your SQL. Autocomplete suggests keywords, table names and the columns of tables your query mentions.
3. Click **Run**, or press ⌘ ↵ (Ctrl Enter on Windows). The result appears below the editor. Drag the divider to give either more room.

To run just part of a script, highlight it: the button changes to **Run selection**. **Beautify** tidies the SQL up, with one clause per line and keywords in capitals.

## Write SQL for your database

Each data source speaks its own flavor of SQL, and Orcabase sends your SQL to it as written. The main differences you might notice:

| Data source | Dialect | Example: revenue by month |
| --- | --- | --- |
| PostgreSQL | PostgreSQL | `date_trunc('month', created_at)` |
| BigQuery | BigQuery Standard SQL | `DATE_TRUNC(DATE(created_at), MONTH)` |
| DuckDB | DuckDB (close to PostgreSQL) | `date_trunc('month', created_at)` |

Every query returns at most 5,000 rows and stops after 30 seconds. For bigger questions, add up in SQL (with `GROUP BY`) rather than pulling raw rows.

## Save it

When a query is worth keeping, click **Save as query**. It becomes a saved query that you can name, chart and pin to dashboards. See [Queries](https://tini.so/docs/queries).

## Keyboard shortcuts

| Keys | Does |
| --- | --- |
| ⌘ ↵ | Run the query, or the highlighted part |
| ⌘ S | Save (on a saved query’s page) |
| Ctrl Space | Show autocomplete suggestions |

On Windows and Linux, use Ctrl in place of ⌘.

---

Previous: [Explore](https://tini.so/docs/explore.md) · Next: [Queries](https://tini.so/docs/queries.md)

All docs: https://tini.so/llms.txt
