pg_fraction
Adds a fraction data type with arithmetic, comparison, aggregate and B-tree operator-class support.
pg_fraction · Adds a fraction data type with arithmetic, comparison, aggregate and B-tree operator-class support.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100259 | pg_fraction | pg_fraction | 1.0 | TYPE | Unknown | C |
Usage
Sources:
pg_fraction adds a fraction type for exact numerator/denominator storage, basic arithmetic, comparisons, aggregates, casts, and B-tree indexing. Upstream describes it as a sample extension rather than software intended for commercial use.
Core Workflow
Create the extension, store fraction literals, and use the supplied operators:
Fractions are reduced automatically, so equivalent inputs such as 2/4 and 1/2 normalize to the same value.
Important Objects
fractionstores a numerator and denominator and accepts slash-separated input.+,-,*, and/perform fraction arithmetic.- Comparison operators plus the B-tree operator class support ordering and indexes.
max(fraction)andmin(fraction)aggregate fraction values.get_value(fraction)returns an approximate floating-point value.
Limits and Caveats
- The implementation restricts each input component to at most five decimal digits and a value no greater than
99999; arithmetic reports an error when its result exceeds those limits. - The digit check applies to input before reduction, so a large reducible spelling can be rejected even when its normalized result would fit.
- Upstream comparisons convert fractions to floating point. Verify precision and ordering behavior for close or large values; do not use this type where exact rational comparison is a hard requirement.
- Division by zero, sign handling, casts, overflow, dump/restore, and index ordering should be tested against the exact PostgreSQL build before adopting this sample extension.