| 1 |
/* contrib/intagg/intagg--1.1.sql */ |
| 2 |
|
| 3 |
-- complain if script is sourced in psql, rather than via CREATE EXTENSION |
| 4 |
\echo Use "CREATE EXTENSION intagg" to load this file. \quit |
| 5 |
|
| 6 |
-- Internal function for the aggregate |
| 7 |
-- Is called for each item in an aggregation |
| 8 |
CREATE FUNCTION int_agg_state (internal, int4) |
| 9 |
RETURNS internal |
| 10 |
AS 'array_agg_transfn' |
| 11 |
PARALLEL SAFE |
| 12 |
LANGUAGE INTERNAL; |
| 13 |
|
| 14 |
-- Internal function for the aggregate |
| 15 |
-- Is called at the end of the aggregation, and returns an array. |
| 16 |
CREATE FUNCTION int_agg_final_array (internal) |
| 17 |
RETURNS int4[] |
| 18 |
AS 'array_agg_finalfn' |
| 19 |
PARALLEL SAFE |
| 20 |
LANGUAGE INTERNAL; |
| 21 |
|
| 22 |
-- The aggregate function itself |
| 23 |
-- uses the above functions to create an array of integers from an aggregation. |
| 24 |
CREATE AGGREGATE int_array_aggregate(int4) ( |
| 25 |
SFUNC = int_agg_state, |
| 26 |
STYPE = internal, |
| 27 |
FINALFUNC = int_agg_final_array, |
| 28 |
PARALLEL = SAFE |
| 29 |
); |
| 30 |
|
| 31 |
-- The enumeration function |
| 32 |
-- returns each element in a one dimensional integer array |
| 33 |
-- as a row. |
| 34 |
CREATE FUNCTION int_array_enum(int4[]) |
| 35 |
RETURNS setof integer |
| 36 |
AS 'array_unnest' |
| 37 |
LANGUAGE INTERNAL IMMUTABLE STRICT PARALLEL SAFE; |