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 Database Editor.

Databases organize data into tables that can have different structures (e.g., separate tables for product and customer data). Each tab along the top of the interface corresponds to a table—click on a tab to view its data.

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

2. Set the primary key

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

You can configure a table's primary key at any time. Click the table's tab and select Edit Primary Key, then select a field in the New Primary Key dropdown menu.

Edit primary key

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

Use a composite key

If necessary, you can delete a table's primary key. Tables without a primary key are read-only and you cannot make changes to data unless there is a primary key set.

3. Add a record

Click Add row to add a new record 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.

Update text in a cell
  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.