Re: pg_size_pretty, SHOW, and spaces

From: Christoph Berg <myon(at)debian(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: 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-02 09:29:01
Message-ID: 20160802092901.xg5ag7emdxoajhds@msg.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Re: Peter Eisentraut 2016-08-01 <f3e021d3-d843-04a5-d816-6921309b3bf1(at)2ndquadrant(dot)com>
> > PostgreSQL uses the spaces inconsistently, though. pg_size_pretty uses spaces:
> >
> > # select pg_size_pretty((2^20)::bigint);
> > pg_size_pretty
> > ────────────────
> > 1024 kB
>
> because it's "pretty" :)

:)

> > SHOW does not:
> >
> > # show work_mem;
> > work_mem
> > ──────────
> > 1MB
>
> The original idea might have been to allow that value to be passed back
> into the settings system, without having to quote the space. I'm not
> sure, but I think changing that might cause some annoyance.

That's a good argument for keeping it that way, yes.

Re: Bruce Momjian 2016-08-01 <20160801162508(dot)GA28246(at)momjian(dot)us>
> Looking at the Wikipedia article I posted earlier, that also doesn't use
> spaces:
>
> https://en.wikipedia.org/wiki/Binary_prefix

That article has plenty of occurrences of "10 MB" "528 MB/s" and the
like.

> 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.

It's the other way round:

https://en.wikipedia.org/wiki/International_System_of_Units#General_rules

| The value of a quantity is written as a number followed by a space
| (representing a multiplication sign) and a unit symbol; e.g., 2.21 kg
[...]

I'd opt to omit the space anywhere where the value is supposed to be
fed back into the config (SHOW, --parameters), but use the "pretty"
format with space everywhere otherwise (documentation, memory counts
in explain output, pg_size_pretty() etc.)

Christoph

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrew Gierth 2016-08-02 09:52:26 Re: BUG #14268: NULL parameter conversion
Previous Message Jordan Gigov 2016-08-02 08:58:46 Re: BUG #14268: NULL parameter conversion

Browse pgsql-hackers by date

  From Date Subject
Next Message Geoff Winkless 2016-08-02 09:33:11 Re: Why we lost Uber as a user
Previous Message Amit Kapila 2016-08-02 08:40:29 Re: Reviewing freeze map code