Skip to content
pg_when

pg_when

pg_when : Natural language time parsing for PostgreSQL

Overview

ID Extension Package Version Category License Language
1120
pg_when
pg_when
0.1.9
TIME
MIT
Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d--
No
Yes
No
Yes
no
no

manually upgraded PGRX from 0.15.0 to 0.17.0 by Vonng

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
MISS
MISS
MISS
MISS
MISS
Package Version OS ORG SIZE File URL
pg_when_18 0.1.9 el8.x86_64 pigsty 439.5 KiB pg_when_18-0.1.9-1PIGSTY.el8.x86_64.rpm
pg_when_18 0.1.9 el8.aarch64 pigsty 328.5 KiB pg_when_18-0.1.9-1PIGSTY.el8.aarch64.rpm
pg_when_18 0.1.9 el9.x86_64 pigsty 456.1 KiB pg_when_18-0.1.9-1PIGSTY.el9.x86_64.rpm
pg_when_18 0.1.9 el9.aarch64 pigsty 347.9 KiB pg_when_18-0.1.9-1PIGSTY.el9.aarch64.rpm
pg_when_18 0.1.9 el10.x86_64 pigsty 456.2 KiB pg_when_18-0.1.9-1PIGSTY.el10.x86_64.rpm
pg_when_18 0.1.9 el10.aarch64 pigsty 347.6 KiB pg_when_18-0.1.9-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-when 0.1.9 d12.x86_64 pigsty 364.2 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-when 0.1.9 d12.aarch64 pigsty 259.7 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-when 0.1.9 d13.x86_64 pigsty 364.2 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-when 0.1.9 d13.aarch64 pigsty 259.6 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-when 0.1.9 u22.x86_64 pigsty 406.7 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-when 0.1.9 u22.aarch64 pigsty 298.4 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-when 0.1.9 u24.x86_64 pigsty 403.4 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~noble_amd64.deb
postgresql-18-pg-when 0.1.9 u24.aarch64 pigsty 296.1 KiB postgresql-18-pg-when_0.1.9-1PIGSTY~noble_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: official README, official repo

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 distributes ready-made Docker images for PostgreSQL 13 through 18, but the stub should focus on SQL usage rather than container setup.
Last updated on