Re: pg_size_pretty, SHOW, and spaces

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Christoph Berg <myon(at)debian(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Greg Stark <stark(at)mit(dot)edu>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, thomas(dot)berger(at)1und1(dot)de, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_size_pretty, SHOW, and spaces
Date: 2016-08-01 16:25:08
Message-ID: 20160801162508.GA28246@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Mon, Aug 1, 2016 at 01:35:53PM +0200, Christoph Berg wrote:
> Re: Bruce Momjian 2016-07-30 <20160730181643(dot)GD22405(at)momjian(dot)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(at)momjian(dot)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 Content-Type Size
kilo2.diff text/x-diff 82.8 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2016-08-01 18:48:55 Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()
Previous Message Andres Freund 2016-08-01 15:56:02 Re: missing comment in lwlock.c

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2016-08-01 16:38:21 Re: PoC: Make it possible to disallow WHERE-less UPDATE and DELETE
Previous Message Simon Riggs 2016-08-01 16:19:35 Re: PostgreSQL 10 kick-off