Re: [PATCH] expand the units that pg_size_pretty supports on output - Mailing list pgsql-hackers

From David Rowley
Subject Re: [PATCH] expand the units that pg_size_pretty supports on output
Date
Msg-id CAApHDvpWLS695NiyX=nPTU2EcPYX1kPZNw2Td1dYR0bxy9hjOQ@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] expand the units that pg_size_pretty supports on output  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: [PATCH] expand the units that pg_size_pretty supports on output
List pgsql-hackers
 tOn Thu, 8 Jul 2021 at 20:23, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>
> > On Thu, 8 Jul 2021 at 13:31, David Rowley <dgrowleyml@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



pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Small documentation improvement for ALTER SUBSCRIPTION
Next
From: vignesh C
Date:
Subject: Re: Enhanced error message to include hint messages for redundant options error