Skip to content
pg_when

pg_when

pg_when : Natural language time parsing for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
1120
pg_when
pg_when
0.1.9
TIME
MIT
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no

manually upgraded PGRX from 0.15.0 to 0.17.0 by Vonng

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.1.9
18
17
16
15
14
pg_when-
RPM
PIGSTY
0.1.9
18
17
16
15
14
pg_when_$v-
DEB
PIGSTY
0.1.9
18
17
16
15
14
postgresql-$v-pg-when-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
el8.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
el9.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
el9.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
el10.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
el10.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
d12.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
d12.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
d13.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
d13.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
u22.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
u22.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
u24.x86_64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
u24.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
u26.x86_64
MISS
MISS
MISS
MISS
MISS
u26.aarch64
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PIGSTY 0.1.9
PackageVersionOSORGSIZEFile URL
pg_when_180.1.9el8.x86_64pigsty439.5 KiBpg_when_18-0.1.9-1PIGSTY.el8.x86_64.rpm
pg_when_180.1.9el8.aarch64pigsty328.5 KiBpg_when_18-0.1.9-1PIGSTY.el8.aarch64.rpm
pg_when_180.1.9el9.x86_64pigsty456.1 KiBpg_when_18-0.1.9-1PIGSTY.el9.x86_64.rpm
pg_when_180.1.9el9.aarch64pigsty347.9 KiBpg_when_18-0.1.9-1PIGSTY.el9.aarch64.rpm
pg_when_180.1.9el10.x86_64pigsty456.2 KiBpg_when_18-0.1.9-1PIGSTY.el10.x86_64.rpm
pg_when_180.1.9el10.aarch64pigsty347.6 KiBpg_when_18-0.1.9-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-when0.1.9d12.x86_64pigsty364.2 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-when0.1.9d12.aarch64pigsty259.7 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-when0.1.9d13.x86_64pigsty364.2 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-when0.1.9d13.aarch64pigsty259.6 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-when0.1.9u22.x86_64pigsty406.7 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-when0.1.9u22.aarch64pigsty298.4 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-when0.1.9u24.x86_64pigsty403.4 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~noble_amd64.deb
postgresql-18-pg-when0.1.9u24.aarch64pigsty296.1 KiBpostgresql-18-pg-when_0.1.9-1PIGSTY~noble_arm64.deb
postgresql-18-pg-when0.1.9u26.aarch64pigsty297.6 KiBpostgresql-18-pg-when_0.1.9-2PIGSTY~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 via package name, for the active PG version

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
pig install pg_when -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_when;

Usage

Sources: README, Cargo.toml version 0.1.9, META.json

pg-when parses a constrained natural-language time expression and returns either a PostgreSQL timestamp with time zone or Unix epoch values at different resolutions.

CREATE EXTENSION pg_when;

SELECT when_is('next friday at 8:00 pm in America/New_York');
SELECT seconds_at('next friday at 8:00 pm in America/New_York');
SELECT millis_at('next friday at 8:00 pm in America/New_York');
SELECT micros_at('next friday at 8:00 pm in America/New_York');
SELECT nanos_at('next friday at 8:00 pm in America/New_York');

Supported Query Shape

The parser accepts up to three parts:

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

If no timezone is provided, upstream says the default is UTC.

Common Inputs

  • relative dates: today, tomorrow, last month, this friday, 5 days ago, in 2 years
  • exact dates: YYYY-MM-DD, DD/MM/YYYY, January 10, 2004, 10 Jan 2004
  • relative times: noon, midnight, morning, evening, next hour
  • exact times: 8:30 pm, 15:45
  • time zones: America/New_York, Europe/London, UTC-08:00, UTC+05:30

Examples

SELECT when_is('5 days ago at this hour in Asia/Tokyo');
SELECT when_is('in 2 months at midnight in UTC-8');
SELECT when_is('December 31, 2026 at evening');

Caveats

  • The extension is aimed at the documented grammar above, not arbitrary English.
  • Upstream still lists source/runtime support and Docker image examples from PostgreSQL 13 through 18, but this repo’s package matrix is PostgreSQL 14 through 18 only; do not assume Pigsty packages for PostgreSQL 13.
  • Upstream Cargo.toml currently pins pgrx 0.15.0; this repo’s package metadata records a manual pgrx 0.17.0 upgrade.
Last updated on