# SQL editor

Source: https://cubibase.com/docs/database/sql-editor

Also available: [Markdown version](https://cubibase.com/docs/database/sql-editor.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

Inspect your database with one read-only SQL statement at a time. The editor is for reading; schema changes go through the Database screens — tables, policies, functions, triggers, indexes, types, and views.

## The limits

| Rule | Value |
| --- | --- |
| Statements per run | Exactly one |
| Length | At most 8,000 characters |
| Allowed prefixes | `select`, `with`, `explain`, `show`, `values`, `table` |
| Transaction | Read-only, on the SQL role |
| Statement timeout | 3 seconds |
| Rows returned | At most 200; the response says when it was truncated |

> **important**: The editor will not create a table, add a column, or write a row. Anything that is not a single read-only statement is rejected with `400 invalid_sql`. Schema changes go through the Database screens.

## Useful queries

**Count rows per plan**

```sql
SELECT plan, count(*) AS customers
FROM public.customers
GROUP BY plan
ORDER BY customers DESC;
```

**Inspect your end users**

```sql
SELECT email, is_anonymous, email_verified_at, last_sign_in_at
FROM auth.users
ORDER BY created_at DESC
LIMIT 50;
```

The SQL role can read the managed `auth` and `logs` schemas, so the editor is also how you inspect users, sessions, and request logs. The `vault` schema is not readable from it.

## The response shape

**Result · trimmed**

```json
{
  "columns": ["plan", "customers"],
  "rows": [{ "plan": "pro", "customers": 2 }],
  "truncated": false,
  "rowCount": 2,
  "durationMs": 4,
  "readOnly": true,
  "maxRows": 200
}
```

## Additional resources

- [Tables and columns](https://cubibase.com/docs/database/tables) Where schema changes actually happen.
- [Functions](https://cubibase.com/docs/database/functions) Test your functions here with SELECT.
- [Sessions and tokens](https://cubibase.com/docs/auth/sessions) What the auth tables contain.
