mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 18:43:18 +08:00
As a future replacement for time_bucket(), time_bucket_ng() should support seconds, minutes, and hours. This patch adds this support. The implementation is the same as for time_bucket(). Timezones are not yet supported.
44 lines
2.6 KiB
SQL
44 lines
2.6 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.
|
|
|
|
-- time_bucket_ng() is an _experimental_ new version of time_bucket().
|
|
--
|
|
-- Unlike time_bucket(), time_bucket_ng() supports variable-sized buckets,
|
|
-- such as months and years, and also timezones. Note that the behavior
|
|
-- and the interface of this function are subjects to change. There could
|
|
-- be bugs, and the implementation doesn't claim to be complete. Use at
|
|
-- your own risk.
|
|
--
|
|
-- This function is IMMUTABLE when it doesn't accept timestamptz arguments,
|
|
-- and STABLE otherwise. The reason is that occasionally timezones change.
|
|
-- When dealing with timestamptz's from the far future, it's possible that
|
|
-- between now and then the rules for given TZ will change by local laws. Which
|
|
-- makes the function STABLE by the definition [1].
|
|
--
|
|
-- We don't forbid users to work with timestamptz's from the future, nor warn
|
|
-- about this corner case. This behavior is consistent with PostgreSQL
|
|
-- behavior [2].
|
|
--
|
|
-- [1]: https://www.postgresql.org/docs/current/xfunc-volatility.html
|
|
-- [2]: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES
|
|
--
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts DATE) RETURNS DATE
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_date' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts DATE, origin DATE) RETURNS DATE
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_date' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
|
|
|
|
-- utility functions
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMP) RETURNS TIMESTAMP
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_timestamp' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMP, origin TIMESTAMP) RETURNS TIMESTAMP
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_timestamp' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ) RETURNS TIMESTAMPTZ
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_timestamptz' LANGUAGE C STABLE PARALLEL SAFE STRICT;
|
|
|
|
CREATE OR REPLACE FUNCTION timescaledb_experimental.time_bucket_ng(bucket_width INTERVAL, ts TIMESTAMPTZ, origin TIMESTAMPTZ) RETURNS TIMESTAMPTZ
|
|
AS '@MODULE_PATHNAME@', 'ts_time_bucket_ng_timestamptz' LANGUAGE C STABLE PARALLEL SAFE STRICT;
|