bytes_concat_agg

Concatenates BYTES chunks in aggregate input order, preserving an aggregate ORDER BY clause when supplied.

Example

Local

1
-- Build a WETH / 0.3% / USDC Uniswap V3 packed path
2
SELECT hex(bytes_concat_agg(chunk ORDER BY position)) AS path
3
FROM (
4
VALUES
5
(1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS::BYTES),
6
(2, evm_pack_uint_be(3000::UINT256, 3)),
7
(3, '0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'::ADDRESS::BYTES)
8
) AS pieces(position, chunk);
9
-- => [{"path":"C02AAA39B223FE8D0A0E5C4F27EAD9083C756CC2000BB8A0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

bytes_concat_agg(BYTES) #

Returns the ordered concatenation of BYTES chunks. Empty groups and groups containing NULL return NULL.

Inputs

Name Type Use
chunk BYTES

BYTES fragment. Supply aggregate ORDER BY for deterministic framing; any NULL chunk makes the group result NULL.

required positional

Returns

Name Type
bytes BYTES

Concatenated bytes. Returns BYTES in aggregate order. Empty groups and groups containing at least one NULL return NULL.

Examples

Local SQL

1
-- A NULL fragment poisons the aggregate instead of being skipped
2
SELECT hex(bytes_concat_agg(chunk ORDER BY position)) AS encoded
3
FROM (
4
VALUES (1, '0x01'::BYTES), (2, NULL::BYTES), (3, '0x02'::BYTES)
5
) AS pieces(position, chunk);
6
-- => [{"encoded":null}]
Notebook ready in readonly mode.

Category and tags

Category
EVM utilities
Tag
Bytes
Tag
Aggregate
Tag
Types