Parameters
Introduction
With parameters, you can inject data into your SQL statement. You can input plain text or numbers, or inject data from Sheets or another block.
Add data from Sheets
To add data from Sheets, follow these steps:
-
Add a parameter to your SQL.
select e.* from dummy.events AS e where 1=1 and e.email like '%{{email}}%' limit 200
-
As soon as you add a parameter to your SQL, a "Parameters" section appears in SeekWell. Select Sheets as the Type.
-
Select the Spreadsheet you want to grab the parameter value from and the cell using A1 notation (for example,
Sheet1!A1
). You can only use a single cell, except in the case of Postgres and Snowflake. If you need to reference multiple cells, useand / or
statements. -
Run the query and results appear based on your parameters.
Lists and tables (Postgres and Snowflake only)
You can also use a Sheet range, or more than one cell, to generate a SQL list (for example, where some_column in (1, 2, 3)
). To use the list in your query, simply add the parameter (no parens, quotes, etc. needed), for example:
select *
from some_table as d
where d.some_column in {{vals}}
If you need more power in querying a Sheet, refer to 🔍 Query Sheets using SQL.
Setting parameters in the URL
You can set parameters in the URL to share links that automatically update the parameters:
https://app.seekwell.io/run/<youruuid>?param1=value1¶m2=value2
Or for a 📋 Forms:
https://app.seekwell.io/form/<youruuid>?param1=value1¶m2=value2
Select the "Share block" link in the top right to get the link with the current parameter values:
Trigger actions on load
To run a block as soon as the app finishes loading, set runOnLoad=1
.
You can also set a special parameter of viewNumber to control the view when a block loads. For example, ?viewNumber=3
will show a full-screen table. Here are the other options:
-
Split
-
Full screen code
-
Full screen table
-
Charts
For example, the link below will set the param "email" to [email protected], run the block, and display the results full screen:
https://app.seekwell.io/run/<yourblockid>?&runOnLoad=1&viewNumber=3&[email protected]
Creating a dropdown / select parameter
-
Create a block with the options you want in the dropdown (see video below).
-
Choose "Select" as the parameter type.
-
Choose the block you created in the first step and the column from that block you want to use in the dropdown.
You can even create a dropdown impromptu with SQLite and the "Sheets / CSV / Block" source type.
SELECT *
FROM (VALUES ("dog"),
("cat"),
("bird")
) as a
Drill Downs
-
Add a parameter to your select statement, for example:
SELECT {{email}}, r.revenue FROM dummy.revenue AS r WHERE 1=1 limit 2
-
Select the Drill Down type.
-
Insert the SQL that will display and select the block you want to drill to. For example, if you were selecting email from a table and wanted to drill to another block that had email as a parameter, your SQL would be
email
. The parameter names must be the same between the two blocks. -
The parameter will now show as a link in the results and selecting on the link will drill to the block you set in the parameter.
Editable
You can use the "editable" parameter type to make columns values editable. You can then pass the entire row into another block to perform SQL updates. For example, say you had a users
table that had the columns plan
and email
.
Create a block to update the plan with the following SQL:
update dummy.users
set plan = '{{plan}}'
where email = '{{email}}'
Add a parameter in your select
(for example, {{plan}}
), choose the "Editable" parameter type, and select the block you created above as the "Update with" block. The "SQL" field is the SQL to get the current value.
select d.email, {{plan}}
from dummy.users AS d
order by created_on desc
limit 100
Hovering over an editable cell changes the background to black, and you can now change the value. Select the Save icon to run your update block.
The entire row is passed into the update block, so the email
in the row you updated is used as a parameter in the update block. In our case, the update SQL becomes:
update dummy.users
set plan = 'premium'
where email = '[email protected]'
Subqueries
You can add the SQL of any block into another block for use in a subselect or CTE. Once a subquery is added, you can select it to drill down to the child query.
Parent Block
SELECT u.email, u.channel, r.revenue
FROM dummy.users AS u inner join
({{revenue}}) as r on u.email = r.email
WHERE 1=1
Select the "Subquery" parameter type and select the block whose SQL you want to add from the drop-down:
Child Block (revenue)
SELECT
r.email,
sum(revenue) as revenue
FROM dummy.revenue AS r
WHERE 1=1
group by 1
order by 2 desc
limit 200
Intercom
See Intercom for details on this type.