bytes_concat_agg

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

Example

Runs locally

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

API reference

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

Runs locally

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