Re: [PATCH] Add get_bytes() and set_bytes() functions - Mailing list pgsql-hackers

From Joel Jacobson
Subject Re: [PATCH] Add get_bytes() and set_bytes() functions
Date
Msg-id 81b14d60-e200-4644-8145-10da654ed334@app.fastmail.com
Whole thread Raw
In response to Re: [PATCH] Add get_bytes() and set_bytes() functions  ("Joel Jacobson" <joel@compiler.org>)
Responses Re: [PATCH] Add get_bytes() and set_bytes() functions
List pgsql-hackers
On Wed, Aug 14, 2024, at 19:25, Joel Jacobson wrote:
> What do we want to happen if passing a numeric with decimal digits,
> to decimal_to_bytes()? It must be an error, right?
>
> Example: SELECT decimal_to_bytes(1.23);

Hmm, an error feels quite ugly on second thought.
Would be nicer if all numerics could be represented,
in a bytea representation that is meaningful to other systems.

I think we need a tuple somehow.

Example:

SELECT numeric_to_bytes(223195403574957);
(\xcafebabedeadbeef,0,false)

SELECT numeric_to_bytes(-223195403574957);
(\xcafebabedeadbeef,0,true)

SELECT numeric_to_bytes(2231954035749.57);
(\xcafebabedeadbeef,2,false)

SELECT numeric_from_bytes('\xcafebabedeadbeef'::bytea,0,false);
223195403574957

SELECT numeric_from_bytes('\xcafebabedeadbeef'::bytea,0,true);
-223195403574957

SELECT numeric_from_bytes('\xcafebabedeadbeef'::bytea,2,false);
2231954035749.57

But then what about Inf,-Inf,NaN?

Regards,
Joel



pgsql-hackers by date:

Previous
From: SAMEER KUMAR
Date:
Subject: Re: Adding clarification to description of IPC wait events XactGroupUpdate and ProcArrayGroupUpdate
Next
From: Peter Eisentraut
Date:
Subject: Re: Variable renaming in dbcommands.c