mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-07-13 14:19:16 +02:00
ee303739d3
. replace CREATE OR REPLACE AGGREGATE with a separate DROP and CREATE . add DROP for all CREATE OPERATORs . use IMMUTABLE and STRICT instead of WITH (isStrict) . add IMMUTABLE and STRICT to int_array_aggregate's accumulator function Gregory Stark
38 lines
1.1 KiB
MySQL
38 lines
1.1 KiB
MySQL
-- Adjust this setting to control where the objects get created.
|
|
SET search_path = public;
|
|
|
|
SET autocommit TO 'on';
|
|
|
|
-- Internal function for the aggregate
|
|
-- Is called for each item in an aggregation
|
|
CREATE OR REPLACE FUNCTION int_agg_state (int4, int4)
|
|
RETURNS int4
|
|
AS 'MODULE_PATHNAME','int_agg_state'
|
|
LANGUAGE 'C' IMMUTABLE STRICT;
|
|
|
|
-- Internal function for the aggregate
|
|
-- Is called at the end of the aggregation, and returns an array.
|
|
CREATE OR REPLACE FUNCTION int_agg_final_array (int4)
|
|
RETURNS int4[]
|
|
AS 'MODULE_PATHNAME','int_agg_final_array'
|
|
LANGUAGE 'C' IMMUTABLE STRICT;
|
|
|
|
-- The aggration funcion.
|
|
-- uses the above functions to create an array of integers from an aggregation.
|
|
DROP AGGREGATE int_array_aggregate(int4);
|
|
CREATE AGGREGATE int_array_aggregate (
|
|
BASETYPE = int4,
|
|
SFUNC = int_agg_state,
|
|
STYPE = int4,
|
|
FINALFUNC = int_agg_final_array,
|
|
INITCOND = 0
|
|
);
|
|
|
|
-- The enumeration function
|
|
-- returns each element in a one dimentional integer array
|
|
-- as a row.
|
|
CREATE OR REPLACE FUNCTION int_array_enum(int4[])
|
|
RETURNS setof integer
|
|
AS 'MODULE_PATHNAME','int_enum'
|
|
LANGUAGE 'C' IMMUTABLE STRICT;
|