mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 19:13:16 +08:00
There is no CREATE OR REPLACE AGGREGATE which means that the only way to replace an aggregate is to DROP then CREATE which is problematic as it will fail if the previous version of the aggregate has dependencies. This commit makes sure aggregates are not dropped and recreated every time. NOTE that WHEN CREATING NEW FUNCTIONS in sql/aggregates.sql you should also make sure they are created in an update script so that both new users and people updating from a previous version get the new function. sql/aggregates.sql is run only once when TimescaleDB is installed and is not rerun during updates that is why everything created there should also be in an update file. Fixes #612
49 lines
2.2 KiB
SQL
49 lines
2.2 KiB
SQL
-- This file is meant to contain aggregate functions that need to be created only
|
|
-- once and not recreated during updates.
|
|
-- There is no CREATE OR REPLACE AGGREGATE which means that the only way to replace
|
|
-- an aggregate is to DROP then CREATE which is problematic as it will fail
|
|
-- if the previous version of the aggregate has dependencies.
|
|
-- NOTE that WHEN CREATING NEW FUNCTIONS HERE you should also make sure they are
|
|
-- created in an update script so that both new users and people updating from a
|
|
-- previous version get the new function
|
|
|
|
|
|
--This aggregate returns the "first" element of the first argument when ordered by the second argument.
|
|
--Ex. first(temp, time) returns the temp value for the row with the lowest time
|
|
CREATE AGGREGATE first(anyelement, "any") (
|
|
SFUNC = _timescaledb_internal.first_sfunc,
|
|
STYPE = internal,
|
|
COMBINEFUNC = _timescaledb_internal.first_combinefunc,
|
|
SERIALFUNC = _timescaledb_internal.bookend_serializefunc,
|
|
DESERIALFUNC = _timescaledb_internal.bookend_deserializefunc,
|
|
PARALLEL = SAFE,
|
|
FINALFUNC = _timescaledb_internal.bookend_finalfunc,
|
|
FINALFUNC_EXTRA
|
|
);
|
|
|
|
--This aggregate returns the "last" element of the first argument when ordered by the second argument.
|
|
--Ex. last(temp, time) returns the temp value for the row with highest time
|
|
CREATE AGGREGATE last(anyelement, "any") (
|
|
SFUNC = _timescaledb_internal.last_sfunc,
|
|
STYPE = internal,
|
|
COMBINEFUNC = _timescaledb_internal.last_combinefunc,
|
|
SERIALFUNC = _timescaledb_internal.bookend_serializefunc,
|
|
DESERIALFUNC = _timescaledb_internal.bookend_deserializefunc,
|
|
PARALLEL = SAFE,
|
|
FINALFUNC = _timescaledb_internal.bookend_finalfunc,
|
|
FINALFUNC_EXTRA
|
|
);
|
|
|
|
-- This aggregate partitions the dataset into a specified number of buckets (nbuckets) ranging
|
|
-- from the inputted min to max values.
|
|
CREATE 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
|
|
);
|