Re: [PATCH] Add function to_oct

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Kirk Wolak <wolakk(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Eric Radman <ericshane(at)eradman(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add function to_oct
Date: 2023-08-20 15:25:51
Message-ID: 20230820152551.GB290672@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 19, 2023 at 08:35:46AM +0100, Dean Rasheed wrote:
> I note that there are no tests for negative inputs.

I added some in v8.

> Doing a quick test, shows that this changes the current behaviour,
> because all inputs are now treated as 64-bit:
>
> HEAD:
>
> select to_hex((-1234)::int);
> to_hex
> ----------
> fffffb2e
>
> With patch:
>
> select to_hex((-1234)::int);
> to_hex
> ------------------
> fffffffffffffb2e

Good catch. In v8, I fixed this by first casting the input to uint32 for
the 32-bit versions of the functions. This prevents the conversion to
uint64 from setting the rest of the bits. AFAICT this behavior is pretty
well defined in the standard.

> The way that negative inputs are handled really should be documented,
> or at least it should include a couple of examples.

I used your suggestion and noted that the output is the two's complement
representation [0].

[0] https://postgr.es/m/CAEZATCVbkL1ynqpsKiTDpch34%3DSCr5nnau%3DnfNmiy2nM3SJHtw%40mail.gmail.com

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v8-0001-add-to_binary-and-to_oct.patch text/x-diff 9.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-08-20 15:48:48 Re: Oversight in reparameterize_path_by_child leading to executor crash
Previous Message Masahiko Sawada 2023-08-20 15:20:45 Re: [PoC] pg_upgrade: allow to upgrade publisher node