Warehouse Tables
Objects from the main Benchling database are periodically synced to the warehouse to make them available for queries. It may take time (usually a few minutes, up to 24 hours) for data to appear in the warehouse.
If you need additional help for the Benchling Insights application, see Use Benchling Insights to view experimental and operational data in the Help Center.
Why isn’t a table appearing in my warehouse?
Warehouse tables only appear once there are rows to create for that table! That means if you create a new schema, it won’t appear in the warehouse until you’ve also created an object under that schema.
$raw Tables
There are usually two tables within the warehouse for a single schema in Benchling: one with and without the suffix $raw after the schema name. Generally speaking, the views are “cleaned up” versions of the raw data (e.g. archived items are hidden, only results from reviewed notebook entries are shown, etc). Deciding which table version to use depends on your specific use case.
For most users, we recommend using the “cleaned up” views, particularly if you are just getting started. These views are designed to present only the most useful data for the most common warehouse use cases, but might suffer from performance issues in some particularly complex edge cases. Users that are using particularly complex queries or who need optimal performance, we recommend using the unprocessed $raw table versions instead.
Some important considerations when using $raw tables:
$rawtables also include various “other” columns starting with ”_”; these columns exist for internal use, and shouldn’t be used in any query.- The
_pkeycolumn does not represent the primary key for a particular table. All tables will have an initialidcolumn which represents that particular table’s primary key. - The
acl_resource_idcolumn exists for internal use, and should not be used in any query. - The stability and semantics of these columns do not fall under our Stability guidelines, and may change without warning.
Joins
The Benchling warehouse, like other relational databases, stores data across multiple tables. But what happens when you want to have a single table representing rows from several tables at once? This is where SQL joins can help.
There are already a lot of great tutorials elsewhere on using joins in SQL. Here we’ll just introduce a couple of examples relevant to interacting with data across multiple Benchling warehouse tables.
Simple joins
Notebook entry metadata is stored in the entry warehouse table, but an entry is related to other concepts (and tables) in Benchling, for instance:
- a Folder and Project that the entry is stored in
- a User (or App) that created the entry
- (optional) a schema that the entry was registered in
The example below shows how to use a series of joins between the entry table and folder, project, principal (this table includes both users and Benchling Apps, as either can author an entry) and schema tables. We’ll just return the name from these joined tables, but you could return other fields by including them in the SELECT statement.
What if we also want to list out the names of all the authors for each notebook entry? One way to do this is to create a Common Table Expression (CTE) where we join the author and principal tables and combine the authors names together using string_agg. We’ll call this CTE author_names:
Advanced joins
Recursive queries are a useful way to summarize hierarchies, where the data forms a tree or graph-like structure. Some example of where a recursive query may come in handy in Benchling are:
- summarizing Benchling Inventory locations (for example: Plate -> Shelf -> Freezer -> Lab -> Building)
- summarizing folder locations of Benchling objects - which we’ll explore in more detail in this section
To create a list of Notebook entries and their corresponding locations, start by defining a new recursive CTE - called folder_path here. Folder names and IDs are in the folder warehouse table:
Now that we have a list of folders and their corresponding paths, create a second CTE (called entries) by joining the folder_path CTE to the entry table to give the complete list of Notebook Entries and folder locations.
For more details on recursive queries, refer to the PostgreSQL documentation here.
Metadata Tables
In the Insights product, Benchling currently limits the access to many Postgres metadata tables found in information_schema and pg_catalog . The following are the metadata tables currently available to users for convenience: