time_bucket_ng() function is an experimental version of the
time_bucket() function. It introduced some new capabilities,
such as monthly buckets and timezone support. Those features are now part of the
This section describes a feature that is deprecated on Timescale. We strongly recommend that you do not use this feature in a production environment. If you need more information, contact us.
time_bucket_ng() functions are similar, but not completely compatible. There are two main differences.
time_bucket_ng() doesn't work with timestamps prior to
Secondly, the default
origin values differ.
time_bucket() uses an origin
date of January 3, 2000, for buckets shorter than a month.
uses an origin date of January 1, 2000, for all bucket sizes.
|A PostgreSQL time interval for how long each bucket is
|DATE, TIMESTAMP or TIMESTAMPTZ
|The timestamp to bucket
|Should be the same as
|Buckets are aligned relative to this timestamp
|The name of the timezone. The argument can be specified only if the type of
ts is TIMESTAMPTZ
For backward compatibility with
timezone argument is
optional. However, it is required for time buckets that are less than 24 hours.
If you call the TIMESTAMPTZ-version of the function without the
argument, the timezone defaults to the session's timezone and so the function
can't be used with continuous aggregates. Best practice is to use
time_bucket_ng(interval, timestamptz, text) and specify the timezone.
The function returns the bucket's start time. The return value type is the
In this example,
time_bucket_ng() is used to create bucket data in three month
This example uses
time_bucket_ng() to bucket data in one year intervals:
To split time into buckets,
time_bucket_ng() uses a starting point in time
origin. The default origin is
time_bucket_ng cannot use
timestamps earlier than
Going back in time from
origin isn't usually possible, especially when you
consider timezones and daylight savings time (DST). Note also that there is no
reasonable way to split time in variable-sized buckets (such as months) from an
origin defaults to the first day of the month.
To bypass named limitations, you can override the default
This example shows how
time_bucket_ng() is used to bucket data
by months in a specified timezone:
You can use
time_bucket_ng() with continuous aggregates. This example tracks
the temperature in Moscow over seven day intervals:
by_range dimension builder is an addition to TimescaleDB 2.13. For simpler cases, like this one, you can also create the hypertable using the old syntax:
For more information, see the continuous aggregates documentation.
time_bucket_ng() supports months and timezones, continuous aggregates cannot always be used with monthly buckets or buckets with timezones.
This table shows which
time_bucket_ng() functions can be used in a continuous aggregate:
|Available in continuous aggregate
|Buckets by seconds, minutes, hours, days, and weeks
|2.4.0 and later
|Buckets by months and years
|2.6.0 or later
|2.6.0 or later
|Specify custom origin
|2.7.0 or later
Found an issue on this page?Report an issue!