pg_num2int_direct_comp
pg_num2int_direct_comp · Exact numeric/float-to-integer comparison operators that preserve index use.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101920 | pg_num2int_direct_comp | pg_num2int_direct_comp | 1.0.1 | FUNC | MIT | C |
PostgreSQL · 12, 13, 14, 15, 16, 17, 18, 19
Usage
Sources:
- README.md
- CHANGELOG.md
- pg_num2int_direct_comp.control
- pg_num2int_direct_comp–1.0.0.sql
- pg_num2int_direct_comp–1.0.0–1.0.1.sql
pg_num2int_direct_comp 1.0.1 adds exact comparisons between numeric/floating values and integers, with planner simplification and B-tree/hash family integration. The first tagged and PGXN release is dated November 27, 2026. It requires PostgreSQL 16–19; earlier development snapshots had broader compatibility claims.
Compare Without Casting the Indexed Column
A superuser creates this relocatable C extension. No preload is required. Operator lookup depends on the installation schema being available in the query’s search path.
The last expression is false with the extension’s exact cross-type operator. An appropriate comparison with a constant may simplify to an integer predicate, making an existing index usable; the planner still chooses the plan based on costs.
Objects and Configuration
The release defines equality and ordering comparisons in both directions for numeric, float4 and float8 against int2, int4 and int8, plus comparison support functions and B-tree/hash family entries. Numeric-to-float comparison is outside this surface. These operators change comparison semantics at precision boundaries; validate representative filters, joins, NULL cases and hash results.
pg_num2int_direct_comp.enable_support_functions defaults on and is user-settable. Turning it off disables planner simplification, not the installed cross-type operators or all their semantics:
Same-Version Snapshot Upgrade
A January development snapshot also called itself 1.0.0. The November release fixes wrong-result cases involving reversed comparisons, integer limits, floating equality/hash consistency and NULL handling, plus missing merge-join metadata and drop cleanup. Checking only the extension version cannot distinguish the old snapshot.
There is no SQL upgrade script from that snapshot. Upstream requires dropping and recreating the extension. Inventory dependent objects and the installed source revision first, preserve their definitions and data, and plan that replacement in a maintenance window. Do not treat an unrestricted cascading drop as a safe migration. The release’s cleanup event trigger removes its built-in operator-family entries when the extension is dropped.
Released 1.0.0 to 1.0.1
Version 1.0.1 supplies the direct path ALTER EXTENSION pg_num2int_direct_comp UPDATE TO '1.0.1'; fresh installations use the 1.0.0 base script followed by the upgrade. It fixes mixed integer-width/float merge-operator-family connections and adjusts numeric-constant inference. The January same-version development snapshot above still needs separate identification; it is not automatically equivalent to released 1.0.0.
Released 1.0.0 actually registered pg_num2int_direct_comp.enableSupportFunctions; the documented snake_case name was an unregistered custom setting with no effect in that version. Version 1.0.1 registers pg_num2int_direct_comp.enable_support_functions and reserves the prefix, without an old-name alias. Explicitly migrate or reset old configuration before upgrading, or the old setting warns and is discarded while the new setting defaults to on.