pg_extra_time
pg_extra_time
pg_extra_time : Some date time functions and operators that,
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4220 | pg_extra_time | pg_extra_time | 2.0.0 | UTIL | PostgreSQL | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgsql_tweaks periods temporal_tables pg_cron gzip bzip zstd http |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 2.0.0 | 18 17 16 15 14 | pg_extra_time | - |
| RPM | PGDG | 2.0.0 | 18 17 16 15 14 | pg_extra_time_$v | - |
| DEB | PIGSTY | 2.0.0 | 18 17 16 15 14 | postgresql-$v-pg-extra-time | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
el8.aarch64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
el9.x86_64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
el9.aarch64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
el10.x86_64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
el10.aarch64 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 | PGDG 2.0.0 |
d12.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
d12.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
d13.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
d13.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
u22.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
u22.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
u24.x86_64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
u24.aarch64 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 | PIGSTY 2.0.0 |
Source
pig build pkg pg_extra_time; # build 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_extra_time; # install via package name, for the active PG version
pig install pg_extra_time -v 18; # install for PG 18
pig install pg_extra_time -v 17; # install for PG 17
pig install pg_extra_time -v 16; # install for PG 16
pig install pg_extra_time -v 15; # install for PG 15
pig install pg_extra_time -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION pg_extra_time;Usage
pg_extra_time: Extra date/time functions and operators for PostgreSQL
Convert to Seconds (float)
SELECT to_float('1970-01-01 00:00:00+0'::timestamptz); -- 0.0
SELECT to_float('1 day 1 sec'::interval); -- 86401.0
SELECT to_float('[2024-06-06 05:58:00,2024-06-06 06:00:10]'::tstzrange); -- 130.0Cast syntax also works:
SELECT '1970-01-01 01:03:01+00'::timestamptz::float; -- 3181.00
SELECT '1 day 1 sec 200 ms'::interval::float; -- 86401.2Convert to Days
SELECT days('[2024-06-06,2024-06-08 06:00]'::tstzrange); -- 3.25 (fractional days)
SELECT whole_days('[2024-06-06,2024-06-08 18:00]'::tstzrange); -- 2 (whole days only)
SELECT days('10 days 12 hours'::interval); -- 10.5
SELECT whole_days('10 days 20 hours'::interval); -- 10Extract Interval from Range
SELECT to_interval('[2024-01-01,2024-01-05]'::tstzrange); -- 4 daysEach Functions (generate series from ranges)
SELECT * FROM each_subperiod('[2024-01-01,2024-01-05]'::tstzrange, '1 day'::interval);Operators
-- Range duration as float (seconds)
SELECT '[epoch,1970-01-01T01:03:01+00]'::tstzrange::float;
-- Interval as float (seconds)
SELECT '10 seconds 100 milliseconds'::interval::float; -- 10.100Last updated on