2016-06-07 11:25:55 -04:00
|
|
|
/* contrib/intagg/intagg--1.1.sql */
|
2002-02-24 22:45:27 -05:00
|
|
|
|
2011-10-12 15:45:03 -04:00
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
|
|
|
\echo Use "CREATE EXTENSION intagg" to load this file. \quit
|
|
|
|
|
|
2002-02-24 22:45:27 -05:00
|
|
|
-- Internal function for the aggregate
|
|
|
|
|
-- Is called for each item in an aggregation
|
2011-02-13 21:24:14 -05:00
|
|
|
CREATE FUNCTION int_agg_state (internal, int4)
|
2008-11-14 14:58:45 -05:00
|
|
|
RETURNS internal
|
|
|
|
|
AS 'array_agg_transfn'
|
2016-06-07 11:25:55 -04:00
|
|
|
PARALLEL SAFE
|
2008-11-14 14:58:45 -05:00
|
|
|
LANGUAGE INTERNAL;
|
2002-02-24 22:45:27 -05:00
|
|
|
|
|
|
|
|
-- Internal function for the aggregate
|
|
|
|
|
-- Is called at the end of the aggregation, and returns an array.
|
2011-02-13 21:24:14 -05:00
|
|
|
CREATE FUNCTION int_agg_final_array (internal)
|
2002-10-18 14:41:22 -04:00
|
|
|
RETURNS int4[]
|
2008-11-14 14:58:45 -05:00
|
|
|
AS 'array_agg_finalfn'
|
2016-06-07 11:25:55 -04:00
|
|
|
PARALLEL SAFE
|
2008-11-14 14:58:45 -05:00
|
|
|
LANGUAGE INTERNAL;
|
2002-02-24 22:45:27 -05:00
|
|
|
|
2004-10-01 11:43:40 -04:00
|
|
|
-- The aggregate function itself
|
2002-02-24 22:45:27 -05:00
|
|
|
-- uses the above functions to create an array of integers from an aggregation.
|
2016-06-07 11:25:55 -04:00
|
|
|
CREATE AGGREGATE int_array_aggregate(int4) (
|
2002-02-24 22:45:27 -05:00
|
|
|
SFUNC = int_agg_state,
|
2008-11-14 14:58:45 -05:00
|
|
|
STYPE = internal,
|
2016-06-07 11:25:55 -04:00
|
|
|
FINALFUNC = int_agg_final_array,
|
|
|
|
|
PARALLEL = SAFE
|
2002-02-24 22:45:27 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- The enumeration function
|
2005-01-27 16:35:40 -05:00
|
|
|
-- returns each element in a one dimensional integer array
|
2002-02-24 22:45:27 -05:00
|
|
|
-- as a row.
|
2011-02-13 21:24:14 -05:00
|
|
|
CREATE FUNCTION int_array_enum(int4[])
|
2002-10-18 14:41:22 -04:00
|
|
|
RETURNS setof integer
|
2008-11-14 14:58:45 -05:00
|
|
|
AS 'array_unnest'
|
2016-06-07 11:25:55 -04:00
|
|
|
LANGUAGE INTERNAL IMMUTABLE STRICT PARALLEL SAFE;
|