mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 10:33:27 +08:00
From PG12 on, CREATE OR REPLACE is supported for aggregates, therefore, since we have dropped support for PG11, we can avoid going through the rigamarole of having our aggregates in a separate file from the functions we define to support them. Nor do we need to handle aggregates separately from other functions as their creation is now idempotent.
49 lines
2.5 KiB
SQL
49 lines
2.5 KiB
SQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_sfunc (state INTERNAL, val DOUBLE PRECISION, MIN DOUBLE PRECISION, MAX DOUBLE PRECISION, nbuckets INTEGER)
|
|
RETURNS INTERNAL
|
|
AS '@MODULE_PATHNAME@', 'ts_hist_sfunc'
|
|
LANGUAGE C IMMUTABLE PARALLEL SAFE;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_combinefunc(state1 INTERNAL, state2 INTERNAL)
|
|
RETURNS INTERNAL
|
|
AS '@MODULE_PATHNAME@', 'ts_hist_combinefunc'
|
|
LANGUAGE C IMMUTABLE PARALLEL SAFE;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_serializefunc(INTERNAL)
|
|
RETURNS bytea
|
|
AS '@MODULE_PATHNAME@', 'ts_hist_serializefunc'
|
|
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_deserializefunc(bytea, INTERNAL)
|
|
RETURNS INTERNAL
|
|
AS '@MODULE_PATHNAME@', 'ts_hist_deserializefunc'
|
|
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.hist_finalfunc(state INTERNAL, val DOUBLE PRECISION, MIN DOUBLE PRECISION, MAX DOUBLE PRECISION, nbuckets INTEGER)
|
|
RETURNS INTEGER[]
|
|
AS '@MODULE_PATHNAME@', 'ts_hist_finalfunc'
|
|
LANGUAGE C IMMUTABLE PARALLEL SAFE;
|
|
|
|
-- We started using CREATE OR REPLACE AGGREGATE for aggregate creation once the syntax was fully supported
|
|
-- as it is easier to support idempotent changes this way. This will allow for changes to functions supporting
|
|
-- the aggregate, and, for instance, the definition and inclusion of inverse functions for window function
|
|
-- support. However, it should still be noted that changes to the data structures used for the internal
|
|
-- state of the aggregate must be backwards compatible and the old format must be accepted by any new functions
|
|
-- in order for them to continue working with Continuous Aggregates, where old states may have been materialized.
|
|
|
|
-- This aggregate partitions the dataset into a specified number of buckets (nbuckets) ranging
|
|
-- from the inputted min to max values.
|
|
CREATE OR REPLACE AGGREGATE histogram (DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION, INTEGER) (
|
|
SFUNC = _timescaledb_internal.hist_sfunc,
|
|
STYPE = INTERNAL,
|
|
COMBINEFUNC = _timescaledb_internal.hist_combinefunc,
|
|
SERIALFUNC = _timescaledb_internal.hist_serializefunc,
|
|
DESERIALFUNC = _timescaledb_internal.hist_deserializefunc,
|
|
PARALLEL = SAFE,
|
|
FINALFUNC = _timescaledb_internal.hist_finalfunc,
|
|
FINALFUNC_EXTRA
|
|
);
|