[PATCH] Support casts from numeric to oid8
[PATCH] Support casts from numeric to oid8
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/Re: [PATCH] Support casts from numeric to oid8
От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi Koshi, > Attached is a patch adding an assignment cast. The patch looks correct but its value is debatable. > Is it intentional that this cast fails, even though the value fits in > oid8? My best guess is that no one actually needed this cast before. Could you please describe your case in more detail? As an observation we don't support this for xid8 either: ``` =# SELECT 18446744073709551615::xid8; ERROR: cannot cast type numeric to xid8 ``` -- Best regards, Aleksander Alekseev