pg_rational
pg_rational : bigint fractions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3720 | pg_rational | pg_rational | 0.0.3 |
TYPE | MIT | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.0.3 |
18 17 16 15 14 | pg_rational |
- |
| RPM | PIGSTY | 0.0.3 |
18 17 16 15 14 | pg_rational_$v |
- |
| DEB | PGDG | 0.0.3 |
18 17 16 15 14 | postgresql-$v-rational |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| el8.aarch64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| el9.x86_64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| el9.aarch64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| el10.x86_64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| el10.aarch64 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 | PIGSTY 0.0.3 |
| d12.x86_64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| d12.aarch64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| d13.x86_64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| d13.aarch64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u22.x86_64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u22.aarch64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u24.x86_64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u24.aarch64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u26.x86_64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
| u26.aarch64 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 | PGDG 0.0.3 |
Source
github.com/begriffs/pg_rational
pg_rational-0.0.3.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pg_rational provides exact fractional arithmetic in a fixed 64-bit PostgreSQL type. Use rational for values that must remain exact and for user-defined row ordering where new positions need to be inserted between existing positions without renumbering the table.
Exact Arithmetic
The extension detects arithmetic overflow instead of silently wrapping. ratt is a helper type for tuple coercion:
Conversions are available between integer values, floating-point values, and rationals. Converting a float finds a rational approximation; converting a rational to float loses exactness.
Stable User-Defined Ordering
Use an integer sequence and cast nextval() explicitly. The extension intentionally has no implicit bigint-to-rational conversion because its numerator is limited to the PostgreSQL integer range.
Indexes, Aggregates, and Caveats
rationalsupports btree and hash operator classes, so it can be used in ordered and equality indexes.- The extension supplies
min(rational),max(rational), andsum(rational)aggregates in addition to arithmetic and comparison operators. rational_intermediate(lower, upper)walks a Stern-Brocot tree to find a fraction between its arguments. Extremely narrow ranges take longer, and v0.0.3 has no maximum-depth parameter; do not expose attacker-controlled pathological bounds without a statement timeout.- Values are exact only while arithmetic stays within the type’s numerator and denominator limits. Handle overflow errors rather than falling back silently to floating point.
- Version 0.0.3 is primarily a build-compatibility and documentation release; the user-facing rational arithmetic surface remains stable.