Re: Add support for unit "B" to pg_size_pretty()

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add support for unit "B" to pg_size_pretty()
Date: 2023-02-21 23:47:04
Message-ID: e465dc9e-2d88-6ff7-9fa6-d41ab78dd56e@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 20.02.23 15:34, Justin Pryzby wrote:
> On Mon, Feb 20, 2023 at 07:44:15AM +0100, Peter Eisentraut wrote:
>> This patch adds support for the unit "B" to pg_size_pretty(). This makes it
>
> It seems like what it actually does is to support "B" in pg_size_bytes()
> - is that what you meant ?

yes

> pg_size_pretty() already supports "bytes", so this doesn't actually make
> sizes any more pretty, or evidently change its output at all.

Right, this is for the input side.

>> diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
>> index dbd404101f..9ecd5428c3 100644
>> --- a/src/backend/utils/adt/dbsize.c
>> +++ b/src/backend/utils/adt/dbsize.c
>> @@ -49,6 +49,7 @@ struct size_pretty_unit
>> /* When adding units here also update the error message in pg_size_bytes */
>> static const struct size_pretty_unit size_pretty_units[] = {
>> {"bytes", 10 * 1024, false, 0},
>> + {"B", 10 * 1024, false, 0},
>
> This adds a duplicate line (unitbits=0) where no other existing line
> uses duplicates. If that's intentional, I think it deserves a comment
> highlighting that it's an /*alias*/, and about why that does the right
> thing, either here about or in the commit message.

I have added a comment about that.

Attachment Content-Type Size
v2-0001-Add-support-for-unit-B-to-pg_size_bytes.patch text/plain 5.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-02-21 23:50:06 Re: Possible false valgrind error reports
Previous Message Jacob Champion 2023-02-21 23:03:52 Auth extensions, with an LDAP/SCRAM example [was: Proposal: Support custom authentication methods using hooks]