2. Querying data
Let's query some existing tables
Requirements: You've already created your user account and an organization.
Steps
- From your org dashboard, open the query editor by hitting the
Queries
button.
- Explore the query editor's three sidebars:
Tables
,Queries
, andTemplates
.- The tables sidebar shows all persistences that belong to your organization as well as all
sim
core tables. If you open the query editor from a canvas that contains active persistence components, those tables will also be highlighted as Canvas tables. - The queries sidebar shows all of your queries. Queries are owned at the user-level, not at the org-level, so your collaborators won't see you queries unless you share with them
- The templates sidebar shows some common pre-built queries.
- The tables sidebar shows all persistences that belong to your organization as well as all
- In the query editor, write a simple SQL query like
select * from @sim.blocks limit 10
. Then hit the Run button at the top right. - You can add parameters to a query using the
$
sign. Try replacinglimit 10
withlimit $limit
and then hit the run button again. This time it will ask you to define a type and value for the parameter. Parameters are helpful when you're running the same query frequently with different values and/or prototyping a query you intend to use in an API. - Try adding a new query with the
+
button.
Basic query tips
- It's SQL... We use Pinot's multistage engine. Pinot has docs.
- Always use a limit unless you know your result set is small. We help you with this with the
limit 100
checkbox. - Often the second time you run a query will be significantly faster than the first because the relevant data segments stay loaded in memory.
- Filter with
where
early and often. Pinot has automatic indexing for all columns, so you should easily be able to filter on any column. - Addresses are stored as lower case strings. If you have a checksummed address, convert it to lower case, e.g.,
where account_address = lower('0x48D004a6C175dB331E99BeAf64423b3098357Ae7')
.
You now know how to query existing tables. That'll only get you so far in life...
Updated about 1 month ago
What’s Next