BUG #18677: numeric values in arrays are stored incorrectly - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18677: numeric values in arrays are stored incorrectly
Date
Msg-id 18677-17e55341d56c7719@postgresql.org
Whole thread Raw
Responses Re: BUG #18677: numeric values in arrays are stored incorrectly
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18677
Logged by:          marcel r
Email address:      marcel@vybenetwork.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.


pgsql-bugs by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: BUG #18675: Postgres is not realasing memory causing OOM
Next
From: Muhammad Waqas
Date:
Subject: Re: BUG #18676: Execute function while selecting from table with partial index using this function.