跳转到主要内容

pg_when

Natural language time parsing for PostgreSQL

pg_when : Natural language time parsing for PostgreSQL

Overview

ID Extension Package Version Category License Language
1120 pg_when pg_when 0.1.10 TIME MIT Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-- No Yes No Yes no no
Upstream 0.1.10 supports PostgreSQL 13-18 and pins pgrx 0.18.1; PIGSTY packages PostgreSQL 14-18 with a locked pgrx 0.19.1 compatibility update.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.10 18 17 16 15 14 pg_when -
RPM PIGSTY 0.1.10 18 17 16 15 14 pg_when_$v -
DEB PIGSTY 0.1.10 18 17 16 15 14 postgresql-$v-pg-when -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
el8.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
el9.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
el9.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
el10.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
el10.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
d12.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
d12.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
d13.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
d13.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u22.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u22.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u24.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u24.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u26.x86_64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
u26.aarch64 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10 PIGSTY 0.1.10
Package Version OS ORG SIZE File URL
pg_when_18 0.1.10 el8.x86_64 pigsty 1.0 MiB pg_when_18-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_18 0.1.10 el8.aarch64 pigsty 973.7 KiB pg_when_18-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_18 0.1.10 el9.x86_64 pigsty 1.1 MiB pg_when_18-0.1.10-1PGSTY.el9.x86_64.rpm
pg_when_18 0.1.10 el9.aarch64 pigsty 1.0 MiB pg_when_18-0.1.10-1PGSTY.el9.aarch64.rpm
pg_when_18 0.1.10 el10.x86_64 pigsty 1.1 MiB pg_when_18-0.1.10-1PGSTY.el10.x86_64.rpm
pg_when_18 0.1.10 el10.aarch64 pigsty 1016.2 KiB pg_when_18-0.1.10-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-when 0.1.10 d12.x86_64 pigsty 882.4 KiB postgresql-18-pg-when_0.1.10-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-when 0.1.10 d12.aarch64 pigsty 755.0 KiB postgresql-18-pg-when_0.1.10-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-when 0.1.10 d13.x86_64 pigsty 882.8 KiB postgresql-18-pg-when_0.1.10-1PGSTY~trixie_amd64.deb
postgresql-18-pg-when 0.1.10 d13.aarch64 pigsty 756.4 KiB postgresql-18-pg-when_0.1.10-1PGSTY~trixie_arm64.deb
postgresql-18-pg-when 0.1.10 u22.x86_64 pigsty 977.1 KiB postgresql-18-pg-when_0.1.10-1PGSTY~jammy_amd64.deb
postgresql-18-pg-when 0.1.10 u22.aarch64 pigsty 887.3 KiB postgresql-18-pg-when_0.1.10-1PGSTY~jammy_arm64.deb
postgresql-18-pg-when 0.1.10 u24.x86_64 pigsty 967.6 KiB postgresql-18-pg-when_0.1.10-1PGSTY~noble_amd64.deb
postgresql-18-pg-when 0.1.10 u24.aarch64 pigsty 877.5 KiB postgresql-18-pg-when_0.1.10-1PGSTY~noble_arm64.deb
postgresql-18-pg-when 0.1.10 u26.x86_64 pigsty 964.5 KiB postgresql-18-pg-when_0.1.10-1PGSTY~resolute_amd64.deb
postgresql-18-pg-when 0.1.10 u26.aarch64 pigsty 875.7 KiB postgresql-18-pg-when_0.1.10-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_when_17 0.1.10 el8.x86_64 pigsty 1.0 MiB pg_when_17-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_17 0.1.10 el8.aarch64 pigsty 970.8 KiB pg_when_17-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_17 0.1.10 el9.x86_64 pigsty 1.1 MiB pg_when_17-0.1.10-1PGSTY.el9.x86_64.rpm
pg_when_17 0.1.10 el9.aarch64 pigsty 1.0 MiB pg_when_17-0.1.10-1PGSTY.el9.aarch64.rpm
pg_when_17 0.1.10 el10.x86_64 pigsty 1.1 MiB pg_when_17-0.1.10-1PGSTY.el10.x86_64.rpm
pg_when_17 0.1.10 el10.aarch64 pigsty 1015.4 KiB pg_when_17-0.1.10-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-when 0.1.10 d12.x86_64 pigsty 881.4 KiB postgresql-17-pg-when_0.1.10-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-when 0.1.10 d12.aarch64 pigsty 753.8 KiB postgresql-17-pg-when_0.1.10-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-when 0.1.10 d13.x86_64 pigsty 881.4 KiB postgresql-17-pg-when_0.1.10-1PGSTY~trixie_amd64.deb
postgresql-17-pg-when 0.1.10 d13.aarch64 pigsty 754.7 KiB postgresql-17-pg-when_0.1.10-1PGSTY~trixie_arm64.deb
postgresql-17-pg-when 0.1.10 u22.x86_64 pigsty 976.1 KiB postgresql-17-pg-when_0.1.10-1PGSTY~jammy_amd64.deb
postgresql-17-pg-when 0.1.10 u22.aarch64 pigsty 884.1 KiB postgresql-17-pg-when_0.1.10-1PGSTY~jammy_arm64.deb
postgresql-17-pg-when 0.1.10 u24.x86_64 pigsty 967.1 KiB postgresql-17-pg-when_0.1.10-1PGSTY~noble_amd64.deb
postgresql-17-pg-when 0.1.10 u24.aarch64 pigsty 874.8 KiB postgresql-17-pg-when_0.1.10-1PGSTY~noble_arm64.deb
postgresql-17-pg-when 0.1.10 u26.x86_64 pigsty 962.8 KiB postgresql-17-pg-when_0.1.10-1PGSTY~resolute_amd64.deb
postgresql-17-pg-when 0.1.10 u26.aarch64 pigsty 873.7 KiB postgresql-17-pg-when_0.1.10-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_when_16 0.1.10 el8.x86_64 pigsty 1.0 MiB pg_when_16-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_16 0.1.10 el8.aarch64 pigsty 969.4 KiB pg_when_16-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_16 0.1.10 el9.x86_64 pigsty 1.1 MiB pg_when_16-0.1.10-1PGSTY.el9.x86_64.rpm
pg_when_16 0.1.10 el9.aarch64 pigsty 1.0 MiB pg_when_16-0.1.10-1PGSTY.el9.aarch64.rpm
pg_when_16 0.1.10 el10.x86_64 pigsty 1.1 MiB pg_when_16-0.1.10-1PGSTY.el10.x86_64.rpm
pg_when_16 0.1.10 el10.aarch64 pigsty 1015.0 KiB pg_when_16-0.1.10-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-when 0.1.10 d12.x86_64 pigsty 880.5 KiB postgresql-16-pg-when_0.1.10-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-when 0.1.10 d12.aarch64 pigsty 753.1 KiB postgresql-16-pg-when_0.1.10-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-when 0.1.10 d13.x86_64 pigsty 880.7 KiB postgresql-16-pg-when_0.1.10-1PGSTY~trixie_amd64.deb
postgresql-16-pg-when 0.1.10 d13.aarch64 pigsty 754.5 KiB postgresql-16-pg-when_0.1.10-1PGSTY~trixie_arm64.deb
postgresql-16-pg-when 0.1.10 u22.x86_64 pigsty 974.4 KiB postgresql-16-pg-when_0.1.10-1PGSTY~jammy_amd64.deb
postgresql-16-pg-when 0.1.10 u22.aarch64 pigsty 884.4 KiB postgresql-16-pg-when_0.1.10-1PGSTY~jammy_arm64.deb
postgresql-16-pg-when 0.1.10 u24.x86_64 pigsty 965.9 KiB postgresql-16-pg-when_0.1.10-1PGSTY~noble_amd64.deb
postgresql-16-pg-when 0.1.10 u24.aarch64 pigsty 875.1 KiB postgresql-16-pg-when_0.1.10-1PGSTY~noble_arm64.deb
postgresql-16-pg-when 0.1.10 u26.x86_64 pigsty 961.5 KiB postgresql-16-pg-when_0.1.10-1PGSTY~resolute_amd64.deb
postgresql-16-pg-when 0.1.10 u26.aarch64 pigsty 872.2 KiB postgresql-16-pg-when_0.1.10-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_when_15 0.1.10 el8.x86_64 pigsty 1.0 MiB pg_when_15-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_15 0.1.10 el8.aarch64 pigsty 960.2 KiB pg_when_15-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_15 0.1.10 el9.x86_64 pigsty 1.0 MiB pg_when_15-0.1.10-1PGSTY.el9.x86_64.rpm
pg_when_15 0.1.10 el9.aarch64 pigsty 1022.5 KiB pg_when_15-0.1.10-1PGSTY.el9.aarch64.rpm
pg_when_15 0.1.10 el10.x86_64 pigsty 1.0 MiB pg_when_15-0.1.10-1PGSTY.el10.x86_64.rpm
pg_when_15 0.1.10 el10.aarch64 pigsty 1012.2 KiB pg_when_15-0.1.10-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-when 0.1.10 d12.x86_64 pigsty 875.0 KiB postgresql-15-pg-when_0.1.10-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-when 0.1.10 d12.aarch64 pigsty 748.7 KiB postgresql-15-pg-when_0.1.10-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-when 0.1.10 d13.x86_64 pigsty 874.7 KiB postgresql-15-pg-when_0.1.10-1PGSTY~trixie_amd64.deb
postgresql-15-pg-when 0.1.10 d13.aarch64 pigsty 749.3 KiB postgresql-15-pg-when_0.1.10-1PGSTY~trixie_arm64.deb
postgresql-15-pg-when 0.1.10 u22.x86_64 pigsty 970.2 KiB postgresql-15-pg-when_0.1.10-1PGSTY~jammy_amd64.deb
postgresql-15-pg-when 0.1.10 u22.aarch64 pigsty 877.2 KiB postgresql-15-pg-when_0.1.10-1PGSTY~jammy_arm64.deb
postgresql-15-pg-when 0.1.10 u24.x86_64 pigsty 959.9 KiB postgresql-15-pg-when_0.1.10-1PGSTY~noble_amd64.deb
postgresql-15-pg-when 0.1.10 u24.aarch64 pigsty 868.4 KiB postgresql-15-pg-when_0.1.10-1PGSTY~noble_arm64.deb
postgresql-15-pg-when 0.1.10 u26.x86_64 pigsty 953.1 KiB postgresql-15-pg-when_0.1.10-1PGSTY~resolute_amd64.deb
postgresql-15-pg-when 0.1.10 u26.aarch64 pigsty 866.1 KiB postgresql-15-pg-when_0.1.10-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_when_14 0.1.10 el8.x86_64 pigsty 1.0 MiB pg_when_14-0.1.10-1PGSTY.el8.x86_64.rpm
pg_when_14 0.1.10 el8.aarch64 pigsty 957.8 KiB pg_when_14-0.1.10-1PGSTY.el8.aarch64.rpm
pg_when_14 0.1.10 el9.x86_64 pigsty 1.0 MiB pg_when_14-0.1.10-1PGSTY.el9.x86_64.rpm
pg_when_14 0.1.10 el9.aarch64 pigsty 1020.8 KiB pg_when_14-0.1.10-1PGSTY.el9.aarch64.rpm
pg_when_14 0.1.10 el10.x86_64 pigsty 1.0 MiB pg_when_14-0.1.10-1PGSTY.el10.x86_64.rpm
pg_when_14 0.1.10 el10.aarch64 pigsty 1010.2 KiB pg_when_14-0.1.10-1PGSTY.el10.aarch64.rpm
postgresql-14-pg-when 0.1.10 d12.x86_64 pigsty 872.2 KiB postgresql-14-pg-when_0.1.10-1PGSTY~bookworm_amd64.deb
postgresql-14-pg-when 0.1.10 d12.aarch64 pigsty 746.9 KiB postgresql-14-pg-when_0.1.10-1PGSTY~bookworm_arm64.deb
postgresql-14-pg-when 0.1.10 d13.x86_64 pigsty 872.3 KiB postgresql-14-pg-when_0.1.10-1PGSTY~trixie_amd64.deb
postgresql-14-pg-when 0.1.10 d13.aarch64 pigsty 747.9 KiB postgresql-14-pg-when_0.1.10-1PGSTY~trixie_arm64.deb
postgresql-14-pg-when 0.1.10 u22.x86_64 pigsty 965.2 KiB postgresql-14-pg-when_0.1.10-1PGSTY~jammy_amd64.deb
postgresql-14-pg-when 0.1.10 u22.aarch64 pigsty 875.4 KiB postgresql-14-pg-when_0.1.10-1PGSTY~jammy_arm64.deb
postgresql-14-pg-when 0.1.10 u24.x86_64 pigsty 955.5 KiB postgresql-14-pg-when_0.1.10-1PGSTY~noble_amd64.deb
postgresql-14-pg-when 0.1.10 u24.aarch64 pigsty 866.2 KiB postgresql-14-pg-when_0.1.10-1PGSTY~noble_arm64.deb
postgresql-14-pg-when 0.1.10 u26.x86_64 pigsty 952.0 KiB postgresql-14-pg-when_0.1.10-1PGSTY~resolute_amd64.deb
postgresql-14-pg-when 0.1.10 u26.aarch64 pigsty 863.7 KiB postgresql-14-pg-when_0.1.10-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 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:

pg_when 0.1.10 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.10 declares PostgreSQL 13–18 features and pins pgrx 0.18.1. Pigsty packages cover PostgreSQL 14–18 and apply a locked pgrx 0.19.1 compatibility update.
  • 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.10 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.