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

From Aleksander Alekseev
Subject Re: to_hex() for negative inputs
Date
Msg-id CAJ7c6TNYNiJRYaAnc44Pppmn+qzENDYVT4zwdyLTDZg=G6NT-g@mail.gmail.com
Whole thread Raw
In response to Re: to_hex() for negative inputs  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-hackers
Hi Dean,

> > So in your opinion what is the expected result of to_hex(INT_MIN,
> > with_sign => true)?
> >
>
> "-80000000" or "-0x80000000", depending on whether the prefix is
> requested.

Whether this is the right result is very debatable. 0x80000000 is a
binary representation of -2147483648:

```
(gdb) ptype cur_timeout
type = int
(gdb) p cur_timeout = 0x80000000
$1 = -2147483648
(gdb) p/x cur_timeout
$2 = 0x80000000
```

So what you propose to return is -(-2147483648). For some users this
may be a wanted result, for some it may be not. Personally I would
prefer to get an ERROR in this case. And this is exactly how you end
up with even more flags.

I believe it would be better to let the user write the exact query
depending on what he/she wants.

-- 
Best regards,
Aleksander Alekseev



pgsql-hackers by date:

Previous
From: gkokolatos@pm.me
Date:
Subject: Re: Add LZ4 compression in pg_dump
Next
From: gkokolatos@pm.me
Date:
Subject: Re: Add LZ4 compression in pg_dump