extra_window_functions

extra_window_functions

extra_window_functions : Extra Window Functions for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4720
extra_window_functions
extra_window_functions
1.0
FUNC
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_idkit
pgx_ulid
pg_uuidv7
permuteseq
pg_hashids
sequential_uuids
topn
quantile

no pg14 on el8/9

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
1.0
18
17
16
15
14
extra_window_functions-
RPM
PGDG
1.0
18
17
16
15
14
extra_window_functions_$v-
DEB
PGDG
1.0
18
17
16
15
14
postgresql-$v-extra-window-functions-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
el8.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
el9.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
MISS
el9.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
el10.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
el10.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
d12.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
d12.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
d13.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
d13.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
u22.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
u22.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
u24.x86_64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
u24.aarch64
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PGDG 1.0
PackageVersionOSORGSIZEFile URL
extra_window_functions_181.0el8.x86_64pgdg24.5 KiBextra_window_functions_18-1.0-6PGDG.rhel8.x86_64.rpm
extra_window_functions_181.0el8.aarch64pgdg24.3 KiBextra_window_functions_18-1.0-6PGDG.rhel8.aarch64.rpm
extra_window_functions_181.0el9.x86_64pgdg24.8 KiBextra_window_functions_18-1.0-6PGDG.rhel9.x86_64.rpm
extra_window_functions_181.0el9.aarch64pgdg24.4 KiBextra_window_functions_18-1.0-6PGDG.rhel9.aarch64.rpm
extra_window_functions_181.0el10.x86_64pgdg25.2 KiBextra_window_functions_18-1.0-6PGDG.rhel10.x86_64.rpm
extra_window_functions_181.0el10.aarch64pgdg25.1 KiBextra_window_functions_18-1.0-6PGDG.rhel10.aarch64.rpm
postgresql-18-extra-window-functions1.0d12.x86_64pgdg15.8 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg12+1_amd64.deb
postgresql-18-extra-window-functions1.0d12.aarch64pgdg15.9 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg12+1_arm64.deb
postgresql-18-extra-window-functions1.0d13.x86_64pgdg15.8 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg13+1_amd64.deb
postgresql-18-extra-window-functions1.0d13.aarch64pgdg15.9 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg13+1_arm64.deb
postgresql-18-extra-window-functions1.0u22.x86_64pgdg15.5 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg22.04+1_amd64.deb
postgresql-18-extra-window-functions1.0u22.aarch64pgdg15.6 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg22.04+1_arm64.deb
postgresql-18-extra-window-functions1.0u24.x86_64pgdg15.8 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg24.04+1_amd64.deb
postgresql-18-extra-window-functions1.0u24.aarch64pgdg15.9 KiBpostgresql-18-extra-window-functions_1.0-7.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
extra_window_functions_171.0el8.x86_64pgdg24.3 KiBextra_window_functions_17-1.0-5PGDG.rhel8.x86_64.rpm
extra_window_functions_171.0el8.aarch64pgdg24.2 KiBextra_window_functions_17-1.0-5PGDG.rhel8.aarch64.rpm
extra_window_functions_171.0el9.x86_64pgdg24.7 KiBextra_window_functions_17-1.0-5PGDG.rhel9.x86_64.rpm
extra_window_functions_171.0el9.aarch64pgdg24.5 KiBextra_window_functions_17-1.0-5PGDG.rhel9.aarch64.rpm
extra_window_functions_171.0el10.x86_64pgdg25.1 KiBextra_window_functions_17-1.0-6PGDG.rhel10.x86_64.rpm
extra_window_functions_171.0el10.aarch64pgdg25.1 KiBextra_window_functions_17-1.0-6PGDG.rhel10.aarch64.rpm
postgresql-17-extra-window-functions1.0d12.x86_64pgdg15.8 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg12+1_amd64.deb
postgresql-17-extra-window-functions1.0d12.aarch64pgdg15.8 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg12+1_arm64.deb
postgresql-17-extra-window-functions1.0d13.x86_64pgdg15.8 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg13+1_amd64.deb
postgresql-17-extra-window-functions1.0d13.aarch64pgdg15.9 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg13+1_arm64.deb
postgresql-17-extra-window-functions1.0u22.x86_64pgdg15.6 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg22.04+1_amd64.deb
postgresql-17-extra-window-functions1.0u22.aarch64pgdg15.7 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg22.04+1_arm64.deb
postgresql-17-extra-window-functions1.0u24.x86_64pgdg15.9 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg24.04+1_amd64.deb
postgresql-17-extra-window-functions1.0u24.aarch64pgdg15.9 KiBpostgresql-17-extra-window-functions_1.0-7.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
extra_window_functions_161.0el8.x86_64pgdg24.0 KiBextra_window_functions_16-1.0-3.rhel8.1.x86_64.rpm
extra_window_functions_161.0el8.aarch64pgdg24.0 KiBextra_window_functions_16-1.0-3.rhel8.1.aarch64.rpm
extra_window_functions_161.0el9.x86_64pgdg24.4 KiBextra_window_functions_16-1.0-3.rhel9.1.x86_64.rpm
extra_window_functions_161.0el9.aarch64pgdg24.2 KiBextra_window_functions_16-1.0-3.rhel9.1.aarch64.rpm
extra_window_functions_161.0el10.x86_64pgdg25.1 KiBextra_window_functions_16-1.0-6PGDG.rhel10.x86_64.rpm
extra_window_functions_161.0el10.aarch64pgdg25.1 KiBextra_window_functions_16-1.0-6PGDG.rhel10.aarch64.rpm
postgresql-16-extra-window-functions1.0d12.x86_64pgdg15.8 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg12+1_amd64.deb
postgresql-16-extra-window-functions1.0d12.aarch64pgdg15.8 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg12+1_arm64.deb
postgresql-16-extra-window-functions1.0d13.x86_64pgdg15.8 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg13+1_amd64.deb
postgresql-16-extra-window-functions1.0d13.aarch64pgdg15.9 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg13+1_arm64.deb
postgresql-16-extra-window-functions1.0u22.x86_64pgdg15.6 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg22.04+1_amd64.deb
postgresql-16-extra-window-functions1.0u22.aarch64pgdg15.7 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg22.04+1_arm64.deb
postgresql-16-extra-window-functions1.0u24.x86_64pgdg15.9 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg24.04+1_amd64.deb
postgresql-16-extra-window-functions1.0u24.aarch64pgdg15.9 KiBpostgresql-16-extra-window-functions_1.0-7.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
extra_window_functions_151.0el8.x86_64pgdg24.0 KiBextra_window_functions_15-1.0-2.rhel8.x86_64.rpm
extra_window_functions_151.0el8.aarch64pgdg24.0 KiBextra_window_functions_15-1.0-2.rhel8.aarch64.rpm
extra_window_functions_151.0el9.x86_64pgdg24.8 KiBextra_window_functions_15-1.0-2.rhel9.x86_64.rpm
extra_window_functions_151.0el9.aarch64pgdg24.6 KiBextra_window_functions_15-1.0-2.rhel9.aarch64.rpm
extra_window_functions_151.0el10.x86_64pgdg25.1 KiBextra_window_functions_15-1.0-6PGDG.rhel10.x86_64.rpm
extra_window_functions_151.0el10.aarch64pgdg25.1 KiBextra_window_functions_15-1.0-6PGDG.rhel10.aarch64.rpm
postgresql-15-extra-window-functions1.0d12.x86_64pgdg15.8 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg12+1_amd64.deb
postgresql-15-extra-window-functions1.0d12.aarch64pgdg15.8 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg12+1_arm64.deb
postgresql-15-extra-window-functions1.0d13.x86_64pgdg15.8 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg13+1_amd64.deb
postgresql-15-extra-window-functions1.0d13.aarch64pgdg15.9 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg13+1_arm64.deb
postgresql-15-extra-window-functions1.0u22.x86_64pgdg15.6 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg22.04+1_amd64.deb
postgresql-15-extra-window-functions1.0u22.aarch64pgdg15.7 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg22.04+1_arm64.deb
postgresql-15-extra-window-functions1.0u24.x86_64pgdg15.9 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg24.04+1_amd64.deb
postgresql-15-extra-window-functions1.0u24.aarch64pgdg15.9 KiBpostgresql-15-extra-window-functions_1.0-7.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
extra_window_functions_141.0el8.x86_64pgdg24.4 KiBextra_window_functions_14-1.0-2.rhel8.x86_64.rpm
extra_window_functions_141.0el8.aarch64pgdg23.9 KiBextra_window_functions_14-1.0-2.rhel8.aarch64.rpm
extra_window_functions_141.0el9.aarch64pgdg24.5 KiBextra_window_functions_14-1.0-2.rhel9.aarch64.rpm
extra_window_functions_141.0el10.x86_64pgdg25.1 KiBextra_window_functions_14-1.0-6PGDG.rhel10.x86_64.rpm
extra_window_functions_141.0el10.aarch64pgdg25.1 KiBextra_window_functions_14-1.0-6PGDG.rhel10.aarch64.rpm
postgresql-14-extra-window-functions1.0d12.x86_64pgdg15.7 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg12+1_amd64.deb
postgresql-14-extra-window-functions1.0d12.aarch64pgdg15.8 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg12+1_arm64.deb
postgresql-14-extra-window-functions1.0d13.x86_64pgdg15.7 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg13+1_amd64.deb
postgresql-14-extra-window-functions1.0d13.aarch64pgdg15.8 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg13+1_arm64.deb
postgresql-14-extra-window-functions1.0u22.x86_64pgdg15.7 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg22.04+1_amd64.deb
postgresql-14-extra-window-functions1.0u22.aarch64pgdg15.7 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg22.04+1_arm64.deb
postgresql-14-extra-window-functions1.0u24.x86_64pgdg15.9 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg24.04+1_amd64.deb
postgresql-14-extra-window-functions1.0u24.aarch64pgdg15.8 KiBpostgresql-14-extra-window-functions_1.0-7.pgdg24.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install extra_window_functions;		# install via package name, for the active PG version

pig install extra_window_functions -v 18;   # install for PG 18
pig install extra_window_functions -v 17;   # install for PG 17
pig install extra_window_functions -v 16;   # install for PG 16
pig install extra_window_functions -v 15;   # install for PG 15
pig install extra_window_functions -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION extra_window_functions;

Usage

extra_window_functions: additional window functions for PostgreSQL

Provides window functions that simulate SQL Standard features not available in PostgreSQL syntax, plus novel functions like flip_flop.

CREATE EXTENSION extra_window_functions;

Functions Simulating SQL Standard

FunctionDescription
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)

FunctionDescription
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

FunctionDescription
flip_flop(expr [, expr])Flip-flop operator: returns false until first expr is true, then true until second expr matches

Examples

-- Equivalent to SQL Standard: NTH_VALUE(x, 3) FROM LAST IGNORE NULLS OVER w
SELECT nth_value_from_last_ignore_nulls(x, 3) OVER w FROM t WINDOW w AS (ORDER BY id);

-- Fill forward: carry last non-null value
SELECT lead_ignore_nulls(val, 1) OVER (ORDER BY ts) FROM measurements;
Last updated on