Re: custom function for converting human readable sizes to bytes

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>, "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Guillaume Lelarge <guillaume(at)lelarge(dot)info>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: custom function for converting human readable sizes to bytes
Date: 2016-01-19 13:03:21
Message-ID: CAFj8pRD_rru2G7zd5FiQ9YqtjgJ-yvHHi6NpUPhKRERMw=GF8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2016-01-19 13:42 GMT+01:00 Robert Haas <robertmhaas(at)gmail(dot)com>:

> On Mon, Jan 18, 2016 at 6:56 PM, Vitaly Burovoy
> <vitaly(dot)burovoy(at)gmail(dot)com> wrote:
> > On 1/4/16, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> >> On Mon, Jan 4, 2016 at 10:17 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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(at)postgresql(dot)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.
>

the last patch (pg-size-bytes-08.patch
<http://www.postgresql.org/message-id/attachment/41204/pg-size-bytes-08.patch>)
at 2016-01-04 17:03:02
<http://www.postgresql.org/message-id/CAFj8pRA__Oz8qwoKqseQTcqea4DWe9_hW_vUNZo9J_c7sL3JBg@mail.gmail.com/>
allows negative size

Regards

Pavel

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2016-01-19 13:33:41 Re: Re: [JDBC] 9.4-1207 behaves differently with server side prepared statements compared to 9.2-1102
Previous Message Greg Stark 2016-01-19 12:59:11 Re: [Proposal] Table partition + join pushdown