tOn Thu, 8 Jul 2021 at 20:23, Dean Rasheed <dean.a.rash...@gmail.com> wrote: > > > On Thu, 8 Jul 2021 at 13:31, David Rowley <dgrowle...@gmail.com> wrote: > > Here's a patch which I believe makes pg_size_pretty() and > > pg_size_pretty_numeric() match in regards to negative values. > > LGTM, except I think it's worth also making the numeric code not refer > to bit shifting either. > > > Maybe this plus your regression test would be ok to back-patch? > > +1 > > Here's an update with matching updates to the numeric code, plus the > regression tests.
Looks good. I gave it a bit of exercise by running pgbench and calling this procedure: CREATE OR REPLACE PROCEDURE public.test_size_pretty2() LANGUAGE plpgsql AS $procedure$ declare b bigint; begin FOR i IN 1..1000 LOOP b := 0 - (random() * 9223372036854775807)::bigint; if pg_size_pretty(b) <> pg_size_pretty(b::numeric) then raise notice '%. % != %', b, pg_size_pretty(b), pg_size_pretty(b::numeric); end if; END LOOP; END; $procedure$ It ran 8526956 times, so with the loop that's 8.5 billion random numbers. No variations between the two functions. I got the same after removing the 0 - to test positive numbers. If you like, I can push this in my morning, or if you'd rather do it yourself, please go ahead. David