Retool

Documentation

Welcome to Retool! We're a fast way to build custom internal software.

You'll find the 5 minute demo, quickstart guide, and documentation for each of our connectors and components here. If you've got any questions -- chat with us on the bottom right!

Get Started    Guides

Query anything with SQL

You can query data from non-SQL sources via SQL. If your data isn't from a SQL database, it's probably an array of objects. Retool lets you use SQL to query your data as if they were tables in a database. That means you can query the results of a REST API endpoint, or Google Sheets data, all via SQL.

Writing a query to transform JSON objects

If you have your array of JSON objects handy (eg. in apiData.data), you can query it via a Query JSON with SQL resource:

Filtering an array of objects using SQL

Filtering an array of objects using SQL

It's not _exactly_ SQL

Since the data isn't actually stored in a postgres database, some SQL might not work. If something isn't working exactly as expected, here are the docs:

https://github.com/agershun/alasql/wiki/Sql
https://github.com/agershun/alasql/wiki/SQL-99
https://github.com/agershun/alasql/wiki/SQL-keywords

Examples

Querying raw JSON

select
  *
from
  {{ [{ id: 1, apples: 3 }, { id: 3, apples: 20 }] }}
where
  apples > 5

Joining two JSON arrays

select
  users.*, payments.*
from
  {{ usersApi.data }} as users,
  {{ paymentsApi.data }} as payments
where
  users.id = payments.user_id

Joining across two different database queries

Data from SQL queries are NOT returned as an array of objects!

If you want to use the data as an array of objects, you can use the helper function formatDataAsArray to do so like below.

{{ formatDataAsArray(sqlQuery.data) }}
select
  users.*, payments.*
from
  {{ formatDataAsArray(dbquery1.data) }} as users,
  {{ formatDataAsArray(dbquery2.data) }} as payments
where
  users.id = payments.user_id

Query anything with SQL