bytes_concat_agg
Concatenates BYTES chunks in aggregate input order, preserving an aggregate ORDER BY clause when supplied.
Example
Local
{"id":"sample_yrqb2u","title":"Sample","code":"-- Build a WETH / 0.3% / USDC Uniswap V3 packed path\nSELECT hex(bytes_concat_agg(chunk ORDER BY position)) AS path\nFROM (\n VALUES\n (1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS::BYTES),\n (2, evm_pack_uint_be(3000::UINT256, 3)),\n (3, '0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'::ADDRESS::BYTES)\n) AS pieces(position, chunk);\n-- => [{\"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
{"id":"sample_eq8lq1","title":"Sample","code":"-- A NULL fragment poisons the aggregate instead of being skipped\nSELECT hex(bytes_concat_agg(chunk ORDER BY position)) AS encoded\nFROM (\n VALUES (1, '0x01'::BYTES), (2, NULL::BYTES), (3, '0x02'::BYTES)\n) AS pieces(position, chunk);\n-- => [{\"encoded\":null}]"}
Notebook ready in readonly mode.
Category and tags
- Category
- EVM utilities
- Tag
- Bytes
- Tag
- Aggregate
- Tag
- Deterministic
- Tag
- Types