Skip to content

pg_when

Natural language time parsing for PostgreSQL

pg_when · Natural language time parsing for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1120pg_whenpg_when0.1.11TIMEMITRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--NoYesNoYesnono

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.1.1119 18 17 16 15pg_when-
RPMPIGSTY0.1.1119 18 17 16 15pg_when_$v-
DEBPIGSTY0.1.1119 18 17 16 15postgresql-$v-pg-when-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.10PIGSTY 0.1.10PIGSTY 0.1.10PIGSTY 0.1.10
el8.aarch64N/APIGSTY 0.1.10PIGSTY 0.1.10PIGSTY 0.1.10PIGSTY 0.1.10
el9.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
el9.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
el10.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
el10.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
d12.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
d12.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
d13.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
d13.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u22.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u22.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u24.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u24.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u26.x86_64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
u26.aarch64PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11PIGSTY 0.1.11
PackageVersionOSORGSIZEFile URL
pg_when_190.1.11el9.x86_64pigsty1.2 MiBpg_when_19-0.1.11-1PGSTY.el9.x86_64.rpm
pg_when_190.1.11el9.aarch64pigsty1.1 MiBpg_when_19-0.1.11-1PGSTY.el9.aarch64.rpm
pg_when_190.1.11el10.x86_64pigsty1.2 MiBpg_when_19-0.1.11-1PGSTY.el10.x86_64.rpm
pg_when_190.1.11el10.aarch64pigsty1.1 MiBpg_when_19-0.1.11-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-when0.1.11d12.x86_64pigsty815.1 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-when0.1.11d12.aarch64pigsty723.4 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-when0.1.11d13.x86_64pigsty814.5 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~trixie_amd64.deb
postgresql-19-pg-when0.1.11d13.aarch64pigsty723.8 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~trixie_arm64.deb
postgresql-19-pg-when0.1.11u22.x86_64pigsty904.4 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~jammy_amd64.deb
postgresql-19-pg-when0.1.11u22.aarch64pigsty852.4 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~jammy_arm64.deb
postgresql-19-pg-when0.1.11u24.x86_64pigsty902.9 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~noble_amd64.deb
postgresql-19-pg-when0.1.11u24.aarch64pigsty843.5 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~noble_arm64.deb
postgresql-19-pg-when0.1.11u26.x86_64pigsty889.3 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~resolute_amd64.deb
postgresql-19-pg-when0.1.11u26.aarch64pigsty841.3 KiBpostgresql-19-pg-when_0.1.11-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_when_180.1.10el8.x86_64pigsty1.0 MiBpg_when_18-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_180.1.10el8.aarch64pigsty973.7 KiBpg_when_18-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_180.1.11el9.x86_64pigsty1.2 MiBpg_when_18-0.1.11-1PGSTY.el9.x86_64.rpm
pg_when_180.1.11el9.aarch64pigsty1.1 MiBpg_when_18-0.1.11-1PGSTY.el9.aarch64.rpm
pg_when_180.1.11el10.x86_64pigsty1.2 MiBpg_when_18-0.1.11-1PGSTY.el10.x86_64.rpm
pg_when_180.1.11el10.aarch64pigsty1.1 MiBpg_when_18-0.1.11-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-when0.1.11d12.x86_64pigsty812.2 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-when0.1.11d12.aarch64pigsty724.3 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-when0.1.11d13.x86_64pigsty813.1 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~trixie_amd64.deb
postgresql-18-pg-when0.1.11d13.aarch64pigsty724.4 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~trixie_arm64.deb
postgresql-18-pg-when0.1.11u22.x86_64pigsty901.2 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~jammy_amd64.deb
postgresql-18-pg-when0.1.11u22.aarch64pigsty850.9 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~jammy_arm64.deb
postgresql-18-pg-when0.1.11u24.x86_64pigsty895.7 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~noble_amd64.deb
postgresql-18-pg-when0.1.11u24.aarch64pigsty842.9 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~noble_arm64.deb
postgresql-18-pg-when0.1.11u26.x86_64pigsty885.9 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~resolute_amd64.deb
postgresql-18-pg-when0.1.11u26.aarch64pigsty839.0 KiBpostgresql-18-pg-when_0.1.11-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_when_170.1.10el8.x86_64pigsty1.0 MiBpg_when_17-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_170.1.10el8.aarch64pigsty970.8 KiBpg_when_17-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_170.1.11el9.x86_64pigsty1.1 MiBpg_when_17-0.1.11-1PGSTY.el9.x86_64.rpm
pg_when_170.1.11el9.aarch64pigsty1.1 MiBpg_when_17-0.1.11-1PGSTY.el9.aarch64.rpm
pg_when_170.1.11el10.x86_64pigsty1.1 MiBpg_when_17-0.1.11-1PGSTY.el10.x86_64.rpm
pg_when_170.1.11el10.aarch64pigsty1.1 MiBpg_when_17-0.1.11-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-when0.1.11d12.x86_64pigsty809.8 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-when0.1.11d12.aarch64pigsty722.5 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-when0.1.11d13.x86_64pigsty810.0 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~trixie_amd64.deb
postgresql-17-pg-when0.1.11d13.aarch64pigsty722.5 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~trixie_arm64.deb
postgresql-17-pg-when0.1.11u22.x86_64pigsty898.6 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~jammy_amd64.deb
postgresql-17-pg-when0.1.11u22.aarch64pigsty849.7 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~jammy_arm64.deb
postgresql-17-pg-when0.1.11u24.x86_64pigsty894.2 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~noble_amd64.deb
postgresql-17-pg-when0.1.11u24.aarch64pigsty840.8 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~noble_arm64.deb
postgresql-17-pg-when0.1.11u26.x86_64pigsty883.4 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~resolute_amd64.deb
postgresql-17-pg-when0.1.11u26.aarch64pigsty836.5 KiBpostgresql-17-pg-when_0.1.11-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_when_160.1.10el8.x86_64pigsty1.0 MiBpg_when_16-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_160.1.10el8.aarch64pigsty969.4 KiBpg_when_16-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_160.1.11el9.x86_64pigsty1.1 MiBpg_when_16-0.1.11-1PGSTY.el9.x86_64.rpm
pg_when_160.1.11el9.aarch64pigsty1.1 MiBpg_when_16-0.1.11-1PGSTY.el9.aarch64.rpm
pg_when_160.1.11el10.x86_64pigsty1.1 MiBpg_when_16-0.1.11-1PGSTY.el10.x86_64.rpm
pg_when_160.1.11el10.aarch64pigsty1.1 MiBpg_when_16-0.1.11-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-when0.1.11d12.x86_64pigsty808.8 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-when0.1.11d12.aarch64pigsty719.5 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-when0.1.11d13.x86_64pigsty809.6 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~trixie_amd64.deb
postgresql-16-pg-when0.1.11d13.aarch64pigsty719.4 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~trixie_arm64.deb
postgresql-16-pg-when0.1.11u22.x86_64pigsty897.0 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~jammy_amd64.deb
postgresql-16-pg-when0.1.11u22.aarch64pigsty848.2 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~jammy_arm64.deb
postgresql-16-pg-when0.1.11u24.x86_64pigsty895.9 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~noble_amd64.deb
postgresql-16-pg-when0.1.11u24.aarch64pigsty837.3 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~noble_arm64.deb
postgresql-16-pg-when0.1.11u26.x86_64pigsty882.0 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~resolute_amd64.deb
postgresql-16-pg-when0.1.11u26.aarch64pigsty835.2 KiBpostgresql-16-pg-when_0.1.11-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_when_150.1.10el8.x86_64pigsty1.0 MiBpg_when_15-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_150.1.10el8.aarch64pigsty960.2 KiBpg_when_15-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_150.1.11el9.x86_64pigsty1.1 MiBpg_when_15-0.1.11-1PGSTY.el9.x86_64.rpm
pg_when_150.1.11el9.aarch64pigsty1.1 MiBpg_when_15-0.1.11-1PGSTY.el9.aarch64.rpm
pg_when_150.1.11el10.x86_64pigsty1.1 MiBpg_when_15-0.1.11-1PGSTY.el10.x86_64.rpm
pg_when_150.1.11el10.aarch64pigsty1.1 MiBpg_when_15-0.1.11-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-when0.1.11d12.x86_64pigsty805.9 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-when0.1.11d12.aarch64pigsty719.1 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-when0.1.11d13.x86_64pigsty807.1 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~trixie_amd64.deb
postgresql-15-pg-when0.1.11d13.aarch64pigsty719.5 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~trixie_arm64.deb
postgresql-15-pg-when0.1.11u22.x86_64pigsty896.1 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~jammy_amd64.deb
postgresql-15-pg-when0.1.11u22.aarch64pigsty844.0 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~jammy_arm64.deb
postgresql-15-pg-when0.1.11u24.x86_64pigsty886.1 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~noble_amd64.deb
postgresql-15-pg-when0.1.11u24.aarch64pigsty835.4 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~noble_arm64.deb
postgresql-15-pg-when0.1.11u26.x86_64pigsty879.8 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~resolute_amd64.deb
postgresql-15-pg-when0.1.11u26.aarch64pigsty832.1 KiBpostgresql-15-pg-when_0.1.11-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_when;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_when;		# install by package name

pig install pg_when -v 19;   # install for PG 19
pig install pg_when -v 18;   # install for PG 18
pig install pg_when -v 17;   # install for PG 17
pig install pg_when -v 16;   # install for PG 16
pig install pg_when -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION pg_when;

Usage

Sources:

pg_when 0.1.11 parses a constrained natural-language date and time expression and returns either a PostgreSQL timestamptz value or a Unix epoch value at a selected precision.

CREATE EXTENSION pg_when;

SELECT when_is('next friday at 8:00 pm in America/New_York');
SELECT seconds_at('5 days ago at this hour in Asia/Tokyo');
SELECT millis_at('in 2 months at midnight in UTC-8');
SELECT micros_at('December 31, 2026 at evening');
SELECT nanos_at('last monday at 22:30');

Query Shape

A query can contain a date, a time, and a time zone, joined by at and in:

SELECT when_is('<date> at <time> in <timezone>');
SELECT when_is('<date>');
SELECT when_is('<date> in <timezone>');
SELECT when_is('<time>');
SELECT when_is('<time> in <timezone>');
SELECT when_is('<date> at <time>');

If the time zone is omitted, the parser uses UTC. Supported inputs include relative dates such as tomorrow, last month, and 5 days ago; exact dates in common numeric and month-name forms; relative times such as noon, midnight, and next hour; clock times; IANA time-zone names; and UTC offsets.

Function Index

  • when_is(text) returns timestamptz.
  • seconds_at(text) returns Unix epoch seconds.
  • millis_at(text) returns Unix epoch milliseconds.
  • micros_at(text) returns Unix epoch microseconds.
  • nanos_at(text) returns Unix epoch nanoseconds.

Compatibility and Boundaries

  • The parser implements the documented grammar; it is not a general-purpose natural-language interpreter.
  • Upstream 0.1.11 declares PostgreSQL 13–19 build features and pins pgrx 0.19.3. Server support in a particular binary package depends on that package’s build.
  • pg_when is not relocatable and its control file requires a superuser for CREATE EXTENSION.
  • Invalid text raises an error. All five functions are STRICT, so a null input returns null; nanos_at(text) also errors when the epoch nanoseconds cannot fit in bigint.
  • The 0.1.11 SQL functions are declared IMMUTABLE, but relative expressions such as now, tomorrow, and 5 days ago read the wall clock. Do not use relative-input calls in expression indexes or generated columns, and do not rely on them being reevaluated in cached plans; only fully specified date, time, and time-zone inputs are time-independent.

Table reader