> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hyperfunctions overview

> Functions that enable you to analyze time-series data efficiently. These functions provide essential capabilities for time bucketing, data distribution analysis, and gapfilling.

export const HYPERFUNC = 'hyperfunctions';

export const PG = 'Postgres';

export const TOOLKIT_LONG = 'TimescaleDB Toolkit';

export const TIMESCALE_DB = 'TimescaleDB';

For additional {HYPERFUNC}, use the [{TOOLKIT_LONG}][toolkit] {PG} extension.

## Samples

### Time bucketing with aggregates

Bucket temperature readings into 5-minute intervals and calculate statistics:

```sql theme={"dark"}
SELECT
  time_bucket('5 minutes', time) AS bucket,
  avg(temperature) AS avg_temp,
  first(temperature, time) AS first_temp,
  last(temperature, time) AS last_temp
FROM readings
GROUP BY bucket
ORDER BY bucket DESC;
```

### Gapfilling missing data

Fill gaps in time-series data using last observation carried forward (LOCF):

```sql theme={"dark"}
SELECT
  time_bucket_gapfill('1 hour', time) AS bucket,
  device_id,
  locf(avg(temperature)) AS filled_avg_temp
FROM readings
WHERE time >= NOW() - INTERVAL '1 day'
GROUP BY bucket, device_id
ORDER BY bucket DESC;
```

### Analyzing data distribution

Create a histogram of response times to understand distribution patterns:

```sql theme={"dark"}
SELECT histogram(response_time_ms, 0, 1000, 10)
FROM api_requests
WHERE time > NOW() - INTERVAL '1 day';
```

### Approximate row counting

Get a fast estimate of table size without scanning all data:

```sql theme={"dark"}
SELECT approximate_row_count('readings');
```

## Available functions

### Time series utilities

* [`time_bucket()`][time_bucket]: bucket rows by time interval
* [`first()`][first]: get the first value ordered by another column
* [`last()`][last]: get the last value ordered by another column
* [`days_in_month()`][days_in_month]: calculate days in a month
* [`month_normalize()`][month_normalize]: normalize monthly metrics

### Gapfilling

* [`time_bucket_gapfill()`][time_bucket_gapfill]: bucket time and fill gaps in results
* [`locf()`][locf]: last observation carried forward for filling gaps
* [`interpolate()`][interpolate]: linear interpolation for filling gaps

### Distribution analysis

* [`histogram()`][histogram]: create histograms to visualize data distribution
* [`approximate_row_count()`][approximate_row_count]: fast approximate count of rows in a table

### Additional hyperfunctions

For advanced time-series analysis including statistical analysis, percentile approximation, state tracking, and more,
see the [{TOOLKIT_LONG} API reference][toolkit].

### Deprecated hyperfunctions

* [`time_bucket_ng()`][time_bucket_ng]: next generation time bucketing with additional features

[approximate_row_count]: /api-reference/timescaledb/hyperfunctions/distribution-analysis/approximate_row_count

[days_in_month]: /api-reference/timescaledb/hyperfunctions/time-series-utilities/days_in_month

[distribution-analysis]: /api-reference/timescaledb/hyperfunctions/distribution-analysis

[first]: /api-reference/timescaledb/hyperfunctions/time-series-utilities/first

[gapfilling]: /api-reference/timescaledb/hyperfunctions/time_bucket_gapfill

[histogram]: /api-reference/timescaledb/hyperfunctions/distribution-analysis/histogram

[interpolate]: /api-reference/timescaledb/hyperfunctions/time_bucket_gapfill/interpolate

[last]: /api-reference/timescaledb/hyperfunctions/time-series-utilities/last

[locf]: /api-reference/timescaledb/hyperfunctions/time_bucket_gapfill/locf

[month_normalize]: /api-reference/timescaledb/hyperfunctions/time-series-utilities/month_normalize

[time-series-utilities]: /api-reference/timescaledb/hyperfunctions/time-series-utilities

[time_bucket]: /api-reference/timescaledb/hyperfunctions/time-series-utilities/time_bucket

[time_bucket_gapfill]: /api-reference/timescaledb/hyperfunctions/time_bucket_gapfill/time_bucket_gapfill

[time_bucket_ng]: /api-reference/timescaledb/hyperfunctions/legacy/time_bucket_ng

[toolkit]: /api-reference/timescaledb-toolkit
