BUG #18677: numeric values in arrays are stored incorrectly

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: marcel(at)vybenetwork(dot)com
Subject: BUG #18677: numeric values in arrays are stored incorrectly
Date: 2024-10-29 00:17:33
Message-ID: 18677-17e55341d56c7719@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18677
Logged by: marcel r
Email address: marcel(at)vybenetwork(dot)com
PostgreSQL version: 17.0
Operating system: Linux
Description:

Hi,

I'm working with 256 bit unsigned integers, currently stored as NUMERIC
type.
These values work as individual values, but odd behaviour occurs when the
values are put in an array.

Please see below for the reference.
This was tested on Postgres v17 and v14 with the same behaviour in both.

I noticed that I'm able to convert from text (such as JSONB) to NUMERIC /
uint_256 with no problem.
But the moment these values are inside an array there is some process
involved that sets the numeric value's last digits to 0.

SELECT
jsonb_path_query('605814335005781813025241542787157911726959411820757128006101511735853521072'::JSONB,
'$.number()') AS jsonb_path_value, -- Works.
ARRAY['605814335005781813025241542787157911726959411820757128006101511735853521072']::NUMERIC[]
as direct_numeric_array_outer, -- Inaccurate.
ARRAY['605814335005781813025241542787157911726959411820757128006101511735853521072'::NUMERIC]
as direct_numeric_array_inner, -- Inaccurate.
'605814335005781813025241542787157911726959411820757128006101511735853521072'::NUMERIC
as direct_numeric; -- Works.

{
"jsonb_path_value" :
"605814335005781813025241542787157911726959411820757128006101511735853521072",
"direct_numeric_array_outer" :
"{605,814,335,005,781,800,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000}",
"direct_numeric_array_inner" :
"{605,814,335,005,781,800,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000}",
"direct_numeric" :
605814335005781813025241542787157911726959411820757128006101511735853521072
}

Is it not possible to store these values in an array accurately?

Thank you.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2024-10-29 02:17:03 Re: BUG #18674: Partitioned table doesn't depend on access method it uses
Previous Message Michael Paquier 2024-10-28 23:17:57 Re: pg_rewind fails on Windows where tablespaces are used