IMPLODE

Takes a column of any scalar type and returns an unbounded array. Combined with GROUP BY, this function can be used to reverse an EXPLODE operation.

Behavior Type

Volatile because IMPLODE is not commutative.

Syntax

IMPLODE (input_column [USING PARAMETERS param=value [,...] ] )

Parameters

allow_truncate

Boolean, whether to truncate results if the output length exceeds the column size. If false (the default), the function returns an error if the output array is too large.

Even if this parameter is set to true, if any element of the array is, by itself, too large, the function returns an error. Truncation removes elements from the output array but does not alter individual elements.

max_binary_size The maximum binary size, in bytes, for the returned array. If not specified, the function uses the value of the DefaultArrayBinarySize configuration parameter.

Supported Data Types

The input column may be of any scalar type.

Examples

Consider a table with the following contents:

=> SELECT * FROM filtered;
				
 position | itemprice | itemkey
----------+-----------+---------
        0 |     14.99 |     345
        0 |     27.99 |     567
        1 |     18.99 |     567
        1 |     35.99 |     345
        2 |     14.99 |     123
(5 rows)

The IMPLODE function can assemble the prices into arrays (grouped by keys):

=> SELECT itemkey AS key, IMPLODE(itemprice) AS prices
FROM filtered
GROUP BY itemkey ORDER BY itemkey;
				
 key |    prices
-----+---------------
 123 | [14.99]
 345 | [14.99,35.99]
 567 | [27.99,18.99]
(3 rows)		

See Arrays and Sets (Collections) for a fuller example.