Query builder
Write and save queries to access data from your applications.
Once you have your tables set up and full of data, you might wake up one morning with the wild idea of doing something with your data. Fortunately, Baseten's query interface exists.
The query interface runs PostgreSQL directly on your data, so you have access to the full language.
Please note:
  • All queries through a query interface must return a value or they will fail. So, if adding or removing data, use RETURNING *; at the end of your query.
  • Queries to Baseten tables have a 15-second limit after which they will time out.

Ad-hoc queries

If you want to run a one-off query on a single Baseten Postgres table, click the "query" button on the table list in the UI.
Query launch button
This launches a SQL shell where you can write any query.
SQL interface
This is a complete SQL interface, so you can alter the data and table. Double-check your queries before running them.
Queries written in this interface are not saved. Every time you launch the interface, it will load a default SELECT * query.

Query builder

To write and save more complex SQL, use the query builder, located in the "Queries" tab on the Data page.
Queries created with the Query Builder are accessible in Views to populate user-facing tables.
Query builder
Give your query a meaningful name that will help you identify it in other parts of the baseten application.
Queries written in the query builder can reference multiple tables, and you can change the data source to write queries to external data sources.
If you want to rename a Query, click the three dots next to its name and enter a new name. You'll need to update its name anywhere it is referenced as well.
If you no longer need a query, you can delete it through the same menu. Confirm the deletion in the modal and it will be deleted.

Query Parameters

Use {{}} to add parameters to your query. Parameters are useful when calling a query from a view. For example:
SELECT * from my_table where id={{user_id}};
When testing the query, use the parameter menu in the query builder to add parameters.
Test query with parameters