Skip to main content

Retool Database tutorial

A built-in database solution for Retool organizations.

Retool Database is a fast, secure solution for saving and editing data to use in Retool apps. It combines a PostgreSQL database with a spreadsheet-like interface to manage your data. On Retool Cloud, the underlying database is managed by Retool. On Self-hosted deployments, you host your own PostgreSQL database.

1. Create a table

You can visually interact with your database much like a spreadsheet. Log in to Retool and select the Database tab to access the Retool Database editor.

Databases organize data into tables that can have different schema (e.g., separate tables for product and customer data). The sidebar contains a list of tables in Retool Database. When you open a table, it appears as a tab at the top of the editor for quick access.

Retool Database prompts you to create a new table automatically if one doesn't already exist. You can create an empty table, import existing data in CSV format, or generate a table schema with AI.

2. Set the primary key for the table

A primary key is a field that uniquely identifies each table row (record). Retool automatically includes an id field for the primary key when you create a new table as it's the default option during a CSV import.

Tables without a primary key are read-only and you cannot make changes to data unless there is a primary key set.

You can set or change a table's primary key at any time. Right-click a table tab and select Edit Primary Key, then select a field in the New Primary Key dropdown menu.

If your data doesn't contain a single field that can uniquely identify rows, you can use a composite key. When enabled, you can select multiple fields and use their combined values as a primary key.

3. Add a row

Click Add row to add a new row of data to the table. To quickly edit existing table data, double-click on a cell and update its value, then click Save. You can also interact with certain fields using checkboxes or select options.

  1. Query your data

There is a limit of 1,000 queries per minute for Retool Database that applies across the whole organization.

You write queries to interact with Retool Database data in the same way as any other SQL database resource connected to Retool.

Select the Retool Database resource in the query editor, then specify SQL mode to write raw SQL queries, or GUI mode to construct queries with an interface. As with other SQL databases, you can explore tables in the database.

You can switch between multiple environments from your apps which automatically refreshes any queries you've written. Provided you use the same table names, your app automatically reloads data from the selected environment.