2016-06-07 17:25:55 +02:00
|
|
|
/* contrib/intagg/intagg--1.1.sql */
|
2002-02-25 04:45:27 +01:00
|
|
|
|
2011-10-12 21:45:03 +02: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-25 04:45:27 +01:00
|
|
|
-- Internal function for the aggregate
|
|
|
|
-- Is called for each item in an aggregation
|
2011-02-14 03:24:14 +01:00
|
|
|
CREATE FUNCTION int_agg_state (internal, int4)
|
2008-11-14 20:58:45 +01:00
|
|
|
RETURNS internal
|
|
|
|
AS 'array_agg_transfn'
|
2016-06-07 17:25:55 +02:00
|
|
|
PARALLEL SAFE
|
2008-11-14 20:58:45 +01:00
|
|
|
LANGUAGE INTERNAL;
|
2002-02-25 04:45:27 +01:00
|
|
|
|
|
|
|
-- Internal function for the aggregate
|
|
|
|
-- Is called at the end of the aggregation, and returns an array.
|
2011-02-14 03:24:14 +01:00
|
|
|
CREATE FUNCTION int_agg_final_array (internal)
|
2002-10-18 20:41:22 +02:00
|
|
|
RETURNS int4[]
|
2008-11-14 20:58:45 +01:00
|
|
|
AS 'array_agg_finalfn'
|
2016-06-07 17:25:55 +02:00
|
|
|
PARALLEL SAFE
|
2008-11-14 20:58:45 +01:00
|
|
|
LANGUAGE INTERNAL;
|
2002-02-25 04:45:27 +01:00
|
|
|
|
2004-10-01 17:43:40 +02:00
|
|
|
-- The aggregate function itself
|
2002-02-25 04:45:27 +01:00
|
|
|
-- uses the above functions to create an array of integers from an aggregation.
|
2016-06-07 17:25:55 +02:00
|
|
|
CREATE AGGREGATE int_array_aggregate(int4) (
|
2002-02-25 04:45:27 +01:00
|
|
|
SFUNC = int_agg_state,
|
2008-11-14 20:58:45 +01:00
|
|
|
STYPE = internal,
|
2016-06-07 17:25:55 +02:00
|
|
|
FINALFUNC = int_agg_final_array,
|
|
|
|
PARALLEL = SAFE
|
2002-02-25 04:45:27 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- The enumeration function
|
2005-01-27 22:35:40 +01:00
|
|
|
-- returns each element in a one dimensional integer array
|
2002-02-25 04:45:27 +01:00
|
|
|
-- as a row.
|
2011-02-14 03:24:14 +01:00
|
|
|
CREATE FUNCTION int_array_enum(int4[])
|
2002-10-18 20:41:22 +02:00
|
|
|
RETURNS setof integer
|
2008-11-14 20:58:45 +01:00
|
|
|
AS 'array_unnest'
|
2016-06-07 17:25:55 +02:00
|
|
|
LANGUAGE INTERNAL IMMUTABLE STRICT PARALLEL SAFE;
|