liveBook · Manning

Bucket

As explained in Just Use Postgres!

A time bucket is a fixed temporal interval used to group time-series observations for aggregation.

A time bucket is a fixed temporal interval that groups time-series observations for rollups such as average, maximum, minimum, or count calculations. TimescaleDB's time_bucket function assigns each timestamp to an interval such as 5 minutes, 10 minutes, 3 days, or 1 week. section 9.5.1

time_bucket(bucket_width, ts, [origin, timezone, offset])

Use the function signature to choose an interval and optionally control bucket alignment, timezone, and offset. section 9.5.1

Build a bucketed query by:

  • Applying time_bucket to the timestamp, then grouping by the resulting period and any category such as activity. section 9.5.1

Workout heart-rate chart

A 10-minute bucket produces average and maximum heart rates for each workout period. The returned rows show periods such as 07:00, 07:10, and 07:20, making them suitable for charting.

Continuous aggregate

A five-minute bucket stores each device's minimum heart rate, low-rate count, and total measurements in a continuous aggregate. Querying bucket 02:35 returns five low readings and a true bradycardia_detected flag.

How Just Use Postgres! covers it

How deep it goes
Explains interval assignment, grouping, aggregation, origin, timezone, offset, and continuous-aggregate storage without deeper implementation internals.
Examples
Demonstrates workout charts, weekly activity summaries, shifted weekly origins, local-time calculations, and low-heart-rate detection.
What it assumes
Assumes familiarity with SQL filtering, grouping, aggregate functions, timestamps, and Postgres-style queries.
What you can do after
Apply it via TimescaleDB's time_bucket function to write interval-based SQL summaries and monitoring queries.
How it connects
Connects time-series aggregation with SQL grouping, continuous aggregates, materialized views, hypertables, and time zones.

Also explained in

Compare how 9 books explain bucket →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.