Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat typo error #565

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions learning/how-tos/create-your-first-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ This will create a stacked bar chart showing daily trading volumes by blockchain
<DuneEmbed qID="4601471" vID="7669323" height="400px" />

<Note>

Want to explore more? Try:
- Removing the project filter to see all DEXes
- Changing the time period to 7 days or 90 days
- Adding token filters to focus on specific cryptocurrencies

</Note>

## Next Steps
Expand Down
60 changes: 28 additions & 32 deletions web-app/query-editor/parameters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ title: Using Parameters
description: Parameters allow you to implement variables in certain parts of your Query. This is useful if you want to create a Query that you can reuse with different parameters.
---

Parameters allow you to implement variables in certain parts of your Query. This is useful if you want to create a Query that you can reuse with different parameters.

Parameters in Dune are versatile and can be used in many different ways. You can use them to:

- filter on a specific token
Expand All @@ -16,12 +14,11 @@ Parameters in Dune are versatile and can be used in many different ways. You can

Parameters can be a **single value** or a **list of values** and you can choose **one** or **multiple** values from a pre-defined list of values. This list can be manually defined or populated from a different query.


**To use parameters:**

1. choose the spot in your Query where you want to implement a parameter
2. click on the add parameter button or type ``{{example_parameter_name}}``
3. open the parameter options
2. click on the add parameter button or type `{{example_parameter_name}}`
3. open the parameter options
4. configure your parameter's name, type, and default value

Parameters can be text, numbers,a date, a manual list of values or a list of values from a different query.
Expand All @@ -30,7 +27,7 @@ Parameters can be text, numbers,a date, a manual list of values or a list of val
style={{
position: "relative",
paddingBottom: "calc(50.67708333333333% + 41px)",
height: 0
height: 0,
}}
>
<iframe
Expand All @@ -47,23 +44,21 @@ Parameters can be text, numbers,a date, a manual list of values or a list of val
left: 0,
width: "100%",
height: "100%",
colorScheme: "light"
colorScheme: "light",
}}
/>
</div>


### Freeform parameters

Freeform parameters are useful if you want your users to be able to input any text, number or date value. An example of this would be a parameter that allows users to input an address, a token, or a date.
Freeform parameters are useful if you want your users to be able to input any text, number or date value. An example of this would be a parameter that allows users to input an address, a token, or a date.
The system will automatically detect the type of the value and insert it into the query as the correct type. You can also manually adjust the type within the query by using the `cast` function.


![freeform parameter](../query-editor/images/parameters/freeform-parameter.jpeg)

For example:

``` sql
```sql
-- freeform varbinary parameter
Select * from ethereum.transactions
where "from" = {{address_parameter}}
Expand All @@ -75,7 +70,7 @@ Select * from dex.trades
where amount_usd > {{usd_amount_parameter}}
```

``` sql
```sql
-- freeform date parameter
Select * from dex.trades
where evt_block_time between cast('{{start_date_parameter}}' as timestamp) and cast('{{end_date_parameter}}' as timestamp)
Expand Down Expand Up @@ -104,19 +99,22 @@ where token in (Select token from unnest(split('{{token_list_parameter}}',','))

If you want to allow multiple values, you need to adjust your query for this. Use the `unnest` and `split` functions to turn the columns into useable values.
By default, the values will be inserted into the query as individual columns.
**Example**:
**Example**:
A list of 3 selected values in a parameter called `example_parameter_name` will be inserted into the query like this:

```sql
Select {{example_parameter_name}}
Select {{example_parameter_name}}

/* returns
/* returns
| column1 | column2 | column3 |
| --------- | --------- | --------- |
| WETH-USDC | WBTC-USDC | DAI-USDC |
*/
```
```

Most of the time, you'll want to use the values in a `where in` clause. To do this, you need to use the `unnest` and `split` functions to turn the columns into useable values.
For example:

```sql
Select * from dex.trades
where token_pair in (Select pair from unnest(split('{{example_parameter_name}}',',')) as c(pair))
Expand All @@ -129,8 +127,8 @@ When you manually define a list of values, the list can be text values, numbers,
A very common example of using a manual list is setting the "time granularity" of a dashboard/query.

```sql
Select
date_trunc('{{time_granularity_parameter}}', evt_block_time) as time,
Select
date_trunc('{{time_granularity_parameter}}', evt_block_time) as time,
sum(amount_usd) as amount_usd
from dex.trades
group by 1
Expand All @@ -144,14 +142,13 @@ group by 1

You can use the results of a query as the list of values for a parameter. Doing this allows you to build dynamic dashboards that allow users to choose from a list of values that is populated by a different query. You can choose any query by its query_id and any column by its name. The column data type will be transferred to the parameter.


![parameter from query results](/web-app/query-editor/images/parameters/parameter-query-result.jpeg)


<Note>
**Query results**

The query that you use to populate the list of values does not update automatically. You need to trigger a refresh of the query results to update the list of values. This can happen by either manually refreshing the query results or by setting up a [query schedule](web-app/query-editor/query-scheduler).

</Note>

This feature can be used in all kinds of ways, but here are a few examples:
Expand All @@ -163,37 +160,37 @@ This feature can be used in all kinds of ways, but here are a few examples:

All of these examples could be solved with a manual list, but using a query to populate the list of values allows you to build dynamic dashboards that update automatically. It also can simply make it easier to manage a list of values that is shared between multiple queries.

**Example 1:**
**Example 1:**

You can use a distinct query on dex.trades to populate a list of all projects currently in dex.trades. This list can then be used in multiple queries.

You can use a distinct query on dex.trades to populate a list of all projects currently in dex.trades. This list can then be used in multiple queries.
```sql
Select distinct project from dex.trades
```

[link to dashboard](https://dune.com/dune/query-result-parameter-showcase)


**Example 2:**

Filter on all available perpeptual futures available on synthetix. The master query for this is query_3256054. We can use this query to populate a list of all available perps:

```sql
```sql
--query 3256054 constructs the daily open interest for all synthetix perps
Select
distinct perp_name
from query_3256054
Select
distinct perp_name
from query_3256054
order by perp_name
```

We can then use this list of perps in query_3256054 to make filtering on a specific perp possible:

```sql
...
and perp_name in (Select perp_name from unnest(split('{{perp_name}}',',')) as b(perp_name))
```

[link to query](https://dune.com/queries/3256054/)


### Parameters in query descriptions

You can use parameters in the description of a query. This feature is useful to effortlessly report on the current value of a parameter. For example, you can use this to report on the current value of a parameter that is used in a dashboard.
Expand All @@ -202,7 +199,7 @@ You can use parameters in the description of a query. This feature is useful to
style={{
position: "relative",
paddingBottom: "calc(88.10226155358899% + 41px)",
height: 0
height: 0,
}}
>
<iframe
Expand All @@ -219,7 +216,7 @@ You can use parameters in the description of a query. This feature is useful to
left: 0,
width: "100%",
height: "100%",
colorScheme: "light"
colorScheme: "light",
}}
/>
</div>
Expand All @@ -230,7 +227,6 @@ To use a parameter in a query description:
3. save your query settings
4. your query description will now show the current value of the parameter


### Parameters in dashboards

If you want to use the same parameter between different queries on a dashboard, make sure to use exactly the same settings for the parameter in each query. The parameter will then be shared between the queries and only turn up once in the dashboard's parameter menu. Exactly the same settings means:
Expand All @@ -239,4 +235,4 @@ If you want to use the same parameter between different queries on a dashboard,
- the parameter type is the same
- the parameter default value is the same
- the parameter list of values is the same
- the query id and column name for a list of values from a query is the same
- the query id and column name for a list of values from a query is the same