Skip to content

pg_duration

data type for representing durations

pg_duration · data type for representing durations

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3850pg_durationpg_duration1.0.2TYPEMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.0.219 18 17 16 15pg_duration-
RPMPIGSTY1.0.219 18 17 16 15pg_duration_$v-
DEBPIGSTY1.0.219 18 17 16 15postgresql-$v-pg-duration-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
el8.aarch64N/APIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
el9.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
el9.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
el10.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
el10.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
d12.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
d12.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
d13.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
d13.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u22.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u22.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u24.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u24.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u26.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
u26.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2N/AN/A
PackageVersionOSORGSIZEFile URL
pg_duration_191.0.2el9.x86_64pigsty41.7 KiBpg_duration_19-1.0.2-1PGSTY.el9.x86_64.rpm
pg_duration_191.0.2el9.aarch64pigsty40.7 KiBpg_duration_19-1.0.2-1PGSTY.el9.aarch64.rpm
pg_duration_191.0.2el10.x86_64pigsty41.6 KiBpg_duration_19-1.0.2-1PGSTY.el10.x86_64.rpm
pg_duration_191.0.2el10.aarch64pigsty41.1 KiBpg_duration_19-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-duration1.0.2d12.x86_64pigsty29.3 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-duration1.0.2d12.aarch64pigsty28.9 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-duration1.0.2d13.x86_64pigsty29.3 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-19-pg-duration1.0.2d13.aarch64pigsty29.0 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-19-pg-duration1.0.2u22.x86_64pigsty31.6 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-19-pg-duration1.0.2u22.aarch64pigsty30.8 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-19-pg-duration1.0.2u24.x86_64pigsty30.6 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~noble_amd64.deb
postgresql-19-pg-duration1.0.2u24.aarch64pigsty30.5 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~noble_arm64.deb
postgresql-19-pg-duration1.0.2u26.x86_64pigsty30.6 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-19-pg-duration1.0.2u26.aarch64pigsty30.0 KiBpostgresql-19-pg-duration_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_duration_181.0.2el8.x86_64pigsty40.8 KiBpg_duration_18-1.0.2-1PGSTY.el8.x86_64.rpm
pg_duration_181.0.2el8.aarch64pigsty40.1 KiBpg_duration_18-1.0.2-1PGSTY.el8.aarch64.rpm
pg_duration_181.0.2el9.x86_64pigsty41.6 KiBpg_duration_18-1.0.2-1PGSTY.el9.x86_64.rpm
pg_duration_181.0.2el9.aarch64pigsty40.8 KiBpg_duration_18-1.0.2-1PGSTY.el9.aarch64.rpm
pg_duration_181.0.2el10.x86_64pigsty41.7 KiBpg_duration_18-1.0.2-1PGSTY.el10.x86_64.rpm
pg_duration_181.0.2el10.aarch64pigsty41.3 KiBpg_duration_18-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-duration1.0.2d12.x86_64pigsty29.3 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-duration1.0.2d12.aarch64pigsty28.9 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-duration1.0.2d13.x86_64pigsty29.3 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-18-pg-duration1.0.2d13.aarch64pigsty29.0 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-18-pg-duration1.0.2u22.x86_64pigsty31.6 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-18-pg-duration1.0.2u22.aarch64pigsty30.7 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-18-pg-duration1.0.2u24.x86_64pigsty30.6 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~noble_amd64.deb
postgresql-18-pg-duration1.0.2u24.aarch64pigsty30.4 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~noble_arm64.deb
postgresql-18-pg-duration1.0.2u26.x86_64pigsty30.6 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-18-pg-duration1.0.2u26.aarch64pigsty30.1 KiBpostgresql-18-pg-duration_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_duration_171.0.2el8.x86_64pigsty40.8 KiBpg_duration_17-1.0.2-1PGSTY.el8.x86_64.rpm
pg_duration_171.0.2el8.aarch64pigsty40.1 KiBpg_duration_17-1.0.2-1PGSTY.el8.aarch64.rpm
pg_duration_171.0.2el9.x86_64pigsty41.6 KiBpg_duration_17-1.0.2-1PGSTY.el9.x86_64.rpm
pg_duration_171.0.2el9.aarch64pigsty40.7 KiBpg_duration_17-1.0.2-1PGSTY.el9.aarch64.rpm
pg_duration_171.0.2el10.x86_64pigsty41.6 KiBpg_duration_17-1.0.2-1PGSTY.el10.x86_64.rpm
pg_duration_171.0.2el10.aarch64pigsty41.3 KiBpg_duration_17-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-duration1.0.2d12.x86_64pigsty29.3 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-duration1.0.2d12.aarch64pigsty28.9 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-duration1.0.2d13.x86_64pigsty29.3 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-17-pg-duration1.0.2d13.aarch64pigsty29.0 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-17-pg-duration1.0.2u22.x86_64pigsty32.4 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-17-pg-duration1.0.2u22.aarch64pigsty31.5 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-17-pg-duration1.0.2u24.x86_64pigsty30.5 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~noble_amd64.deb
postgresql-17-pg-duration1.0.2u24.aarch64pigsty30.4 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~noble_arm64.deb
postgresql-17-pg-duration1.0.2u26.x86_64pigsty30.6 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-17-pg-duration1.0.2u26.aarch64pigsty30.1 KiBpostgresql-17-pg-duration_1.0.2-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_duration;		# 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_duration;		# install by package name

pig install pg_duration -v 19;   # install for PG 19
pig install pg_duration -v 18;   # install for PG 18
pig install pg_duration -v 17;   # install for PG 17

Create this extension with:

CREATE EXTENSION pg_duration;

Usage

pg_duration: ISO 8601 duration type for PostgreSQL

The pg_duration extension provides a duration type for storing elapsed time as microseconds in 8 bytes, simpler and more consistently comparable than the built-in interval type.

CREATE EXTENSION pg_duration;

Data Type

The duration type represents absolute elapsed time without calendar components (no months or days). Valid input accepts any PostgreSQL interval syntax that does not exceed hourly units.

SELECT '01:30:00'::duration;
SELECT '2 hours 30 minutes'::duration;

Operators

  • Arithmetic: +, - between durations; *, / by float8; unary -
  • Comparison: <, <=, >, >=, =, <>

Functions

-- Construct from components
SELECT make_duration(hours => 2, mins => 30, secs => 15.5);

-- Check for infinity
SELECT isfinite('01:00:00'::duration);

-- Truncate to precision
SELECT date_trunc('hour', '02:45:30'::duration);

-- Extract subfield
SELECT date_part('minute', '02:45:30'::duration);
SELECT extract_duration('hour', '02:45:30'::duration);

Type Conversions

Durations cast implicitly to interval. Converting interval to duration requires explicit casting.

Aggregates and Indexing

Standard aggregates (avg, count, max, min, sum) and both B-tree and hash indexes are supported.

Table reader