extra_window_functions
extra_window_functions : Extra Window Functions for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4730 | extra_window_functions | extra_window_functions | 2.0 |
FUNC | 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 | tablefunc first_last_agg pg_duckdb argm pg_lake duckdb_fdw |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 2.0 |
18 17 16 15 14 | extra_window_functions |
- |
| RPM | PGDG | 2.0 |
18 17 16 15 14 | extra_window_functions_$v |
- |
| DEB | PGDG | 2.0 |
18 17 16 15 14 | postgresql-$v-extra-window-functions |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| el8.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| el9.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| el9.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| el10.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| el10.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| d12.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| d12.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| d13.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| d13.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u22.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u22.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u24.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u24.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u26.x86_64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
| u26.aarch64 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 | PGDG 2.0 |
Source
github.com/xocolatl/extra_window_functions
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
Provides window functions that simulate SQL Standard features not available in PostgreSQL syntax, plus novel functions like flip_flop.
Functions Simulating SQL Standard
| Function | Description |
|---|---|
lag_ignore_nulls(expr [, offset [, default]]) |
LAG that skips NULL values |
lead_ignore_nulls(expr [, offset [, default]]) |
LEAD that skips NULL values |
first_value_ignore_nulls(expr) |
FIRST_VALUE skipping NULLs |
last_value_ignore_nulls(expr) |
LAST_VALUE skipping NULLs |
nth_value_from_last(expr, offset) |
NTH_VALUE counting from end of frame |
nth_value_ignore_nulls(expr, offset) |
NTH_VALUE skipping NULLs |
nth_value_from_last_ignore_nulls(expr, offset) |
NTH_VALUE from last, skipping NULLs |
Functions Extending SQL Standard (with default values)
| Function | Description |
|---|---|
first_value_ignore_nulls(expr, default) |
FIRST_VALUE with default when out of frame |
last_value_ignore_nulls(expr, default) |
LAST_VALUE with default when out of frame |
nth_value_from_last(expr, offset, default) |
NTH_VALUE from last with default |
nth_value_ignore_nulls(expr, offset, default) |
NTH_VALUE with default, skipping NULLs |
nth_value_from_last_ignore_nulls(expr, offset, default) |
Combined from-last, ignore-nulls, with default |
Non-Standard Functions
| Function | Description |
|---|---|
flip_flop(expr [, expr]) |
Flip-flop operator: returns false until first expr is true, then true until second expr matches |
Examples
Version 2.0 and Window Frames
Version 2.0 adds count_ties(), avg_rank(), avg_percent_rank(), group_number(boolean), run_length(anyelement), run_position(anyelement), ema(double precision, double precision), interpolate(double precision) and most_common(anyelement). These functions cover peer groups, runs, smoothing and interpolation. Their frame and ordering rules differ: choose ORDER BY and the window frame deliberately, and inspect the official function reference rather than treating every function as an aggregate.
The lag example reads the previous non-null value; use last_value_ignore_nulls over a frame ending at the current row when the current non-null value must also be retained. Upgrade existing installations with ALTER EXTENSION extra_window_functions UPDATE TO '2.0'. The relocatable C extension does not require preload; installation normally needs a superuser. Upstream supports PostgreSQL 9.6–19. PostgreSQL 19 provides standard IGNORE NULLS for several functions, while FROM LAST and the extra 2.0 functions have their own uses.