[PATCH] Support casts from numeric to oid8

From: "Koshi Shibagaki (Fujitsu)" <shibagaki(dot)koshi(at)fujitsu(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Support casts from numeric to oid8
Date: 2026-10-23 07:34:27
Message-ID: TY5PR01MB18445597DD6EC7AB442CFA7A8FA642@TY5PR01MB18445.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Is it intentional that this cast fails, even though the value fits in
oid8?

SELECT 18446744073709551615::oid8;
ERROR: cannot cast type numeric to oid8

An integer literal this large is parsed as numeric, so the cast fails
because there is no numeric-to-oid8 cast. '18446744073709551615'::oid8
works.

The built-in signed integer types cannot represent the upper half of
oid8's range. Adding a numeric-to-oid8 cast would allow integer values
across that full range to be converted exactly. This would let N::oid8
work across the full range without changing how the value is written
when it exceeds INT64_MAX.

Attached is a patch adding an assignment cast. An implicit cast would
round fractional values in comparisons. For example,

SELECT 2::oid8 = 1.5;

would return true because 1.5 would be rounded to 2.

The earlier discussion says negative text input wraps around
intentionally [1]. The patch does the same for numeric input.

Comments welcome.

[1] https://www.postgresql.org/message-id/aV2WL3ciOySe0PLi@paquier.xyz

Koshi Shibagaki
FUJITSU LIMITED
https://www.fujitsu.com/

Attachment Content-Type Size
v1-0001-Add-an-assignment-cast-from-numeric-to-oid8.patch application/octet-stream 7.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message David Geier 2026-10-23 07:53:26 Re: Reduce build times of pg_trgm GIN indexes
Previous Message Amit Kapila 2026-10-23 07:01:00 Re: Proposal: Conflict log history table for Logical Replication