pg_stl
pg_stl : Time series analysis functions for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 1130 | pg_stl | pg_stl | 1.0.0 |
TIME | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | timescaledb_toolkit timeseries timescaledb first_last_agg extra_window_functions quantile tdigest |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.0 |
18 17 16 15 14 | pg_stl |
- |
| RPM | PIGSTY | 1.0.0 |
18 17 16 15 14 | pg_stl_$v |
- |
| DEB | PIGSTY | 1.0.0 |
18 17 16 15 14 | postgresql-$v-pg-stl |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| el8.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| el9.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| el9.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| el10.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| el10.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| d12.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| d12.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| d13.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| d13.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u22.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u22.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u24.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u24.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u26.x86_64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
| u26.aarch64 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | PIGSTY 1.0.0 | N/A | N/A |
Source
github.com/nadyaloseva/pg_ts_analysis
pg_stl-1.0.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources: pg_ts_analysis README, SQL definitions, control file.
pg_stl provides time-series analysis functions for PostgreSQL: autocorrelation, partial autocorrelation, STL decomposition, and Holt-Winters forecasting. The upstream README and SQL definitions target PostgreSQL 16+.
Autocorrelation
acf_array(data double precision[], lags integer) returns autocorrelation values for lags 1..lags:
The README describes using peaks at lags such as 7, 14, and 21 as a signal for weekly seasonality. The function returns NULL when the series is too short, lags < 1, or lags >= n.
Partial Autocorrelation
pacf_array(data double precision[], lags integer) returns partial autocorrelation values using the Durbin-Levinson recursion:
Use PACF when you want the direct lag relationship after accounting for shorter lags.
STL Decomposition
stl_decompose decomposes a series into trend, seasonal, and residual arrays:
Signature from the SQL definition:
Use the convenience functions when only one component is needed:
Ordered Collection Helper
The SQL file also defines stl_collect_ordered(tbl regclass, val text, ord text) to collect a column into an ordered double precision[]:
Holt-Winters Forecasting
holt_winters_predict(seasonal_type text, period_length int, start_data_array real[]) forecasts one seasonal cycle ahead. seasonal_type is 'mult' for multiplicative seasonality or 'add' for additive seasonality:
The SQL implementation chooses smoothing coefficients automatically: first by 500 random initializations, then by refinement in 0.001 steps to minimize squared error. The helper holt_winters_mse(...) is present as the error-calculation routine used by the predictor.
Caveats
stl_decomposeexpects adouble precision[]with noNULLvalues.- The README states the series length must be at least
2 * period. seasonalmust be an odd integer greater than or equal to3.- Holt-Winters expects a
real[]input and supports only'mult'and'add'seasonal types.