Skip to content

Dune List of Unique Functions

@kartod@kartod5 charts

Generate time series function

Time series data is a set of values organized in the order in which they occur and arrive for processing. Unlike transactional data in SQL Server, which is not time-based and may be updated often, time series data is typically written once and rarely, if ever, updated.

  • sequence(start, stop)

Generate a sequence of integers from start to stop, incrementing by 1 if start is less than or equal to stop, otherwise -1.

  • sequence(start, stop, step)

Generate a sequence of integers from start to stop, incrementing by step.

JOIN ... USING ...

If several columns have the same names but the datatypes do not match, the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an EQUIJOIN.

  • USING Clause is used to match only one column when more than one column matches.
  • NATURAL JOIN and USING Clause are mutually exclusive.
  • It should not have a qualifier(table name or Alias) in the referenced columns.
  • NATURAL JOIN uses all the columns with matching names and datatypes to join the tables. The USING Clause can be used to specify only those columns that should be used for an EQUIJOIN.

UNNEST (ARRAY[x, y]) AS z

The UNNEST function takes an ARRAY and returns a table with a row for each element in the ARRAY.

Practical Info

  • UNNEST requires an ARRAY as an input but can return a table of any structure.
  • Empty arrays and NULL as an input returns an empty table. An array containing NULL values will produce a row of NULL values.

You can do this with a CROSS JOIN. A cross join will take every individual element of your unnested array and join it back to its parent row. This will create multiple rows for each element of your array but you can then filter it down.


FIRST_VALUE and LAST_VALUE over (...)

The LAST_VALUE() function is a window function that returns the last value in an ordered partition of a result set.

PARTITION BY clause

The PARTITION BY clause distributes rows of the result set into partitions to which the LAST_VALUE() function is applied. If you skip the PARTITION BY clause, the LAST_VALUE() function will treat the whole result set as a single partition.

ORDER BY clause

The ORDER BY clause specifies the logical order of the rows in each partition to which the LAST_VALUE()function is applied.


bytearray_to function

To make it simpler to work with varbinarys we have the following helper functions, which work with these two kinds of representation. They simplify interactions with varbinarys, as they automatically account for the 0x-prefix and use byte index instead of character index.

You can use these function to extract data from undecoded events logs, or calldata. For instance, if you have a function that takes a uint256 as an argument, you can use varbinary_to_uint256 to extract the value from the calldata. You'll oftentimes need to use varbinary_substring to extract the correct part of the calldata or use other bytearray manipulation functions to get the correct value.