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
|
Source
pig build pkg pg_when; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create 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