2002-10-18 20:41:22 +02:00
|
|
|
-- Adjust this setting to control where the objects get created.
|
|
|
|
SET search_path = public;
|
2002-02-25 04:45:27 +01:00
|
|
|
|
|
|
|
-- Internal function for the aggregate
|
|
|
|
-- Is called for each item in an aggregation
|
2005-01-27 22:35:40 +01:00
|
|
|
CREATE OR REPLACE FUNCTION int_agg_state (int4[], int4)
|
|
|
|
RETURNS int4[]
|
2002-10-18 20:41:22 +02:00
|
|
|
AS 'MODULE_PATHNAME','int_agg_state'
|
2005-01-27 22:35:40 +01:00
|
|
|
LANGUAGE 'C';
|
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.
|
2005-01-27 22:35:40 +01:00
|
|
|
CREATE OR REPLACE FUNCTION int_agg_final_array (int4[])
|
2002-10-18 20:41:22 +02:00
|
|
|
RETURNS int4[]
|
|
|
|
AS 'MODULE_PATHNAME','int_agg_final_array'
|
2005-01-27 22:35:40 +01:00
|
|
|
LANGUAGE 'C' STRICT;
|
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.
|
2003-03-20 05:39:27 +01:00
|
|
|
CREATE AGGREGATE int_array_aggregate (
|
2002-02-25 04:45:27 +01:00
|
|
|
BASETYPE = int4,
|
|
|
|
SFUNC = int_agg_state,
|
2005-01-27 22:35:40 +01:00
|
|
|
STYPE = int4[],
|
|
|
|
FINALFUNC = int_agg_final_array
|
2002-02-25 04:45:27 +01:00
|
|
|
);
|
|
|
|
|
2005-01-27 22:35:40 +01:00
|
|
|
-- The aggregate component functions are not designed to be called
|
|
|
|
-- independently, so disable public access to them
|
|
|
|
REVOKE ALL ON FUNCTION int_agg_state (int4[], int4) FROM PUBLIC;
|
|
|
|
REVOKE ALL ON FUNCTION int_agg_final_array (int4[]) FROM PUBLIC;
|
|
|
|
|
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.
|
2002-10-18 20:41:22 +02:00
|
|
|
CREATE OR REPLACE FUNCTION int_array_enum(int4[])
|
|
|
|
RETURNS setof integer
|
|
|
|
AS 'MODULE_PATHNAME','int_enum'
|
2003-03-20 05:39:27 +01:00
|
|
|
LANGUAGE 'C' IMMUTABLE STRICT;
|