pg_extra_time
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_extra_time | 2.1.0 | UTIL | PostgreSQL | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4220 | pg_extra_time | No | Yes | No | Yes | No | Yes | - |
| Related | pgcalendar pg_math pgsql_tweaks pg_rrule |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.1.0 | 1817161514 | pg_extra_time | - |
| RPM | PIGSTY | 2.1.0 | 1817161514 | pg_extra_time_$v | - |
| DEB | PIGSTY | 2.1.0 | 1817161514 | postgresql-$v-pg-extra-time | - |
Build
You can build the RPM / DEB packages for pg_extra_time using pig build:
Install
You can install pg_extra_time directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources: pg_extra_time upstream README, PGXN pg_extra_time.
pg_extra_time provides small SQL functions and casts for date/time, interval, and range calculations that are awkward with PostgreSQL core functions alone.
Convert to Seconds (float)
Use to_float(...) or explicit casts to float/double precision for timestamps, timestamp ranges, and intervals. Timestamp values are measured from the Unix epoch; ranges and intervals are measured by duration in seconds.
Cast syntax also works:
Convert to Days
Use days(...) when fractions matter and whole_days(...) when an integer number of complete days is needed.
whole_days(interval) handles negative intervals by applying the sign after flooring the absolute day count.
Count Date Parts
date_part_parts(part, subpart, timestamp with time zone, timezone) returns how many smaller date parts exist in a larger date part at a given timestamp and timezone. This helps with calculations where a day is not always 24 hours because of DST.
Build And Split Ranges
Use make_tstzrange or make_tsrange to build ranges from a timestamp and interval, including negative intervals.
each_subperiod(tstzrange, interval, round_remainder integer DEFAULT 0) splits a timestamp range into interval-sized chunks. The remainder policy is: 1 rounds up to a full chunk, 0 keeps a partial final chunk, and -1 discards the remainder.
Extract And Remainder Intervals
to_interval(tstzrange) extracts an interval from a timestamp range using month, day, and microsecond units. to_interval(tstzrange, interval[]) accepts explicit units in greatest-first order and rounds down by discarding the remainder.
Use % or modulo(...) when the remainder matters.
Caveats
to_float(tstzrange) and to_float(tsrange) return positive or negative infinity for unbounded ranges and 0 for empty ranges. Integer casts are intentionally not provided; use whole_days(...) when you need integer days. Deprecated aliases such as extract_days(interval) and extract_interval(tstzrange, interval[]) remain for compatibility, but upstream recommends whole_days(...) and to_interval(...) instead.
Reference
Common public functions:
| Function | Use |
|---|---|
current_timezone() | Return the active pg_timezone_names row |
date_part_parts(...) | Count smaller date parts inside larger date parts |
days(...) | Fractional or integer day count, depending on input type |
whole_days(...) | Whole days from intervals or timestamp ranges |
to_float(...) | Seconds from timestamps, timestamp ranges, or intervals |
to_interval(...) | Interval extracted from a tstzrange |
make_tsrange(...) / make_tstzrange(...) | Build ranges from timestamp plus interval |
each_subperiod(...) | Split a tstzrange into subranges |
modulo(...) / % | Remainder after dividing intervals or ranges |
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)