Re: to_hex() for negative inputs - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: to_hex() for negative inputs
Date
Msg-id CAEZATCUE04jLA_+-i80arv4D7H03nKTnEm-H_L7wOXHxTWTNmQ@mail.gmail.com
Whole thread Raw
In response to Re: to_hex() for negative inputs  (Aleksander Alekseev <aleksander@timescale.com>)
Responses Re: to_hex() for negative inputs
List pgsql-hackers
On Tue, 24 Jan 2023 at 13:43, Aleksander Alekseev
<aleksander@timescale.com> wrote:
>
> Adding extra arguments for something the user can implement
> (him/her)self doesn't seem to be a great idea. With this approach we
> may end up with hundreds of arguments one day.
>

I don't see how a couple of extra arguments will expand to hundreds.

> =# select case when sign(x) > 0 then '' else '-' end || to_hex(abs(x))
> from ( values (123), (-123) ) as s(x);
>

Which is broken for INT_MIN:

select case when sign(x) > 0 then '' else '-' end || to_hex(abs(x))
from ( values (-2147483648) ) as s(x);

ERROR:  integer out of range

Part of the reason for implementing this in core would be to save
users from such easy-to-overlook bugs.

Regards,
Dean



pgsql-hackers by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: Re: run pgindent on a regular basis / scripted manner
Next
From: Tom Lane
Date:
Subject: Re: Improve GetConfigOptionValues function