# Tables and the table editor

The **Data → Tables** makes and changes tables, columns, links between tables and indexes without SQL, and lets you look at and edit rows.

Every change runs as the project's own confined database role, so it reaches this project's section of the database and nothing else.

## A new table

Choose **New table**, give it a name and its columns. Names are lowercase letters, digits and underscores, starting with a letter or underscore, up to 63 characters.

A table made here has **row-level security on from the first moment and no rule**. The application is given no rows from it until you write a policy on the **Security → Access rules** page. The table list and the table's own page say so until then. See [Row-level security and policies](https://rezincore.com/docs/database/row-level-security.md).

### Column types

| In the editor | In the database |
|---|---|
| Text | `text` |
| Whole number | `integer` |
| Whole number (large) | `bigint` |
| Exact decimal | `numeric` |
| Decimal (approximate) | `double precision` |
| True or false | `boolean` |
| ID | `uuid` |
| Date and time | `timestamptz` |
| Date | `date` |
| Time of day | `time` |
| JSON | `jsonb` |
| Bytes | `bytea` |
| List of text | `text[]` |

Any other Postgres type can be used by creating the table in [SQL](https://rezincore.com/docs/database/sql.md).

### Defaults

A column can have a ready-made default, a fixed value, or an expression.

| Ready-made default | What it writes |
|---|---|
| Random ID | `gen_random_uuid()` |
| Now | `now()` |
| Today | `current_date` |
| True, False | `true`, `false` |
| Current organization | `core.app_org()`: the organization the request acts for |
| Current person | `core.app_user()`: the signed-in user, or null |
| Empty object | `'{}'::jsonb` |
| Empty list | `'{}'::text[]` |

"Current organization" on an `organization_id` column and "Current person" on an owner column are the two that make policies simple.

### Recommended columns

- A primary key. Realtime and webhooks need one, and so does editing a row.
- `organization_id` (ID, default Current organization) on any table whose rows belong to a tenant. The API fills it in on new rows, and realtime needs it to deliver deletes.

## Changing a table

Open a table and choose **Structure**:

- **Columns**: add, rename, change or remove a column; make it required or optional; set or clear its default.
- **Links to other tables**: a column that must match a row of another table (a foreign key), with what happens when that row is deleted: refuse, delete this row too, or clear the value.
- **Indexes**: an index makes looking rows up by those columns fast. A unique one also refuses two rows with the same values.
- **Realtime**: switch row-change messages on or off for this table. See [Realtime](https://rezincore.com/docs/realtime.md).
- **Rename** and **Delete table**. Deleting removes the table and every row in it and cannot be undone from the console.

A table that your own migrations made is changed in your migrations, not in the editor: the editor shows it but will not alter its structure.

## Rows

The table's own page shows its rows, and you can add, change and delete them. This runs as the project's own role, so it shows every row regardless of policies. It is for the project's members, not a picture of what the application gets.

## Who can do this

Owners and developers of the workspace. Read-only members can look and cannot change anything. Every structure change and row edit is on the project's audit record.
