Re: pg_size_pretty, SHOW, and spaces - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: pg_size_pretty, SHOW, and spaces
Date
Msg-id 20160801162508.GA28246@momjian.us
Whole thread Raw
In response to pg_size_pretty, SHOW, and spaces  (Christoph Berg <myon@debian.org>)
Responses Re: pg_size_pretty, SHOW, and spaces  (Christoph Berg <myon@debian.org>)
List pgsql-hackers
On Mon, Aug  1, 2016 at 01:35:53PM +0200, Christoph Berg wrote:
> Re: Bruce Momjian 2016-07-30 <20160730181643.GD22405@momjian.us>
> > I also just applied a doc patch that increases case and spacing
> > consistency in the use of kB/MB/GB/TB.
>
> Hi,
>
> PostgreSQL uses the spaces inconsistently, though. pg_size_pretty uses spaces:
>
> # select pg_size_pretty((2^20)::bigint);
>  pg_size_pretty
> ────────────────
>  1024 kB
>
> SHOW does not:
>
> # show work_mem;
>  work_mem
> ──────────
>  1MB

Yes, that is inconsistent.  I have updated my attached patch to remove
spaces between the number and the units --- see below.

> The SHOW output is formatted by _ShowOption() using 'INT64_FORMAT "%s"',
> via convert_from_base_unit(). The latter has a comment attached...
> /*
>  * Convert a value in some base unit to a human-friendly unit.  The output
>  * unit is chosen so that it's the greatest unit that can represent the value
>  * without loss.  For example, if the base unit is GUC_UNIT_KB, 1024 is
>  * converted to 1 MB, but 1025 is represented as 1025 kB.
>  */
> ... where the spaces are present again.
>
> General typesetting standard seems to be "1 MB", i.e. to include a
> space between value and unit. (This would also be my preference.)
>
> Opinions? (I'd opt to insert spaces in the docs now, and then see if
> inserting a space in the SHOW output is acceptable for 10.0.)

I went through the docs a few days ago and committed a change to removed
spaces between the number and units in the few cases that had them ---
the majority didn't have spaces.

Looking at the Wikipedia article I posted earlier, that also doesn't use
spaces:

    https://en.wikipedia.org/wiki/Binary_prefix

I think the only argument _for_ spaces is the output of pg_size_pretty()
now looks odd, e.g.:

               10 | 10 bytes       | -10 bytes
             1000 | 1000 bytes     | -1000 bytes
          1000000 | 977KB          | -977KB
       1000000000 | 954MB          | -954MB
    1000000000000 | 931GB          | -931GB
 1000000000000000 | 909TB          | -909TB
                    ^^^^^             ^^^^^

The issue is that we output "10 bytes", not "10bytes", but for units we
use "977KB".  That seems inconsistent, but it is the normal policy
people use.  I think this is because "977KB" is really "977K bytes", but
we just append the "B" after the "K" for bevity.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+                     Ancient Roman grave inscription +

Attachment

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: PostgreSQL 10 kick-off
Next
From: Bruce Momjian
Date:
Subject: Re: PoC: Make it possible to disallow WHERE-less UPDATE and DELETE