Re: custom function for converting human readable sizes to bytes - Mailing list pgsql-hackers

From Robert Haas
Subject Re: custom function for converting human readable sizes to bytes
Date
Msg-id CA+TgmoZFomG4eYorZZGf7pzotG9PxpUhtQvxLfsKiM4iZH8KRQ@mail.gmail.com
Whole thread Raw
In response to Re: custom function for converting human readable sizes to bytes  (Vitaly Burovoy <vitaly.burovoy@gmail.com>)
Responses Re: custom function for converting human readable sizes to bytes  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
On Mon, Jan 18, 2016 at 6:56 PM, Vitaly Burovoy
<vitaly.burovoy@gmail.com> wrote:
> On 1/4/16, Robert Haas <robertmhaas@gmail.com> wrote:
>> On Mon, Jan 4, 2016 at 10:17 AM, Pavel Stehule <pavel.stehule@gmail.com>
>> wrote:
>>> [ new patch ]
>>
>> +         case '-':
>> +             ereport(ERROR,
>> +                     (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
>> +                      errmsg("size cannot be negative")));
>>
>> Why not?  I bet if you copy any - sign to the buffer, this will Just Work.
>
> Hmm. The function's name is pg_size_bytes. How number of bytes can be
> negative? How any length can be negative? If anyone insert '-' sign to
> an argument, it is copy-paste error. I don't see any case where there
> is possible negatives as input value.
>
> I prefer error message instead of getting all relations (by using
> comparison from the initial letter) just because of copy-paste mistake
> or incomplete checking of input values at app-level.

Well, we just recently did this:

commit 8a1fab36aba7506fcf4559c4ef95fcacdd0b439a
Author: Robert Haas <rhaas@postgresql.org>
Date:   Fri Nov 6 11:03:02 2015 -0500
   pg_size_pretty: Format negative values similar to positive ones.
   Previously, negative values were always displayed in bytes, regardless   of how large they were.
   Adrian Vondendriesch, reviewed by Julien Rouhaud and myself

Since we went to the trouble of making the handling of positive and
negative values symmetric for that function, it seems it should be
done here also.  Otherwise, it is asymmetric.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: checkpointer continuous flushing
Next
From: Robert Haas
Date:
Subject: Re: Combining Aggregates