Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zsaq5-0005zy-7Q for pgsql-hackers@arkaria.postgresql.org; Sat, 31 Oct 2015 18:25:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zsaq4-0005Bp-4p for pgsql-hackers@arkaria.postgresql.org; Sat, 31 Oct 2015 18:25:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zsaq3-0005B2-DH; Sat, 31 Oct 2015 18:25:15 +0000 Received: from mimolette.dalibo.net ([212.85.157.144]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Zsapz-0003vT-Ii; Sat, 31 Oct 2015 18:25:14 +0000 Received: from [192.168.0.13] (chello084112069191.1.11.vie.surfer.at [84.112.69.191]) by mimolette.dalibo.net (Postfix) with ESMTPSA id 105A81F103C1; Sat, 31 Oct 2015 19:25:07 +0100 (CET) Subject: Re: [BUGS] BUG #12989: pg_size_pretty with negative values To: "Adrian.Vondendriesch" , "pgsql-bugs@postgresql.org" , pgsql-hackers@postgresql.org References: <20150406173026.2550.39773@wrigleys.postgresql.org> <31955.1428346338@sss.pgh.pa.us> <55FEA38F.40301@credativ.de> Cc: Tom Lane , david.g.johnston@gmail.com, Christian Almeida From: Julien Rouhaud X-Enigmail-Draft-Status: N1110 Message-ID: <56350782.3040400@dalibo.com> Date: Sat, 31 Oct 2015 19:25:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <55FEA38F.40301@credativ.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 20/09/2015 14:16, Adrian.Vondendriesch wrote: > Hi all, > Hello, > Am 06.04.2015 um 20:52 schrieb Tom Lane: >> "David G. Johnston" writes: >>> I'll let a hacker determine whether this is a bug or a feature >>> request though it is a POLA violation in either case. >> >> I'd say it's a feature request --- a perfectly reasonable one, >> but I doubt we'd alter the behavior of the function in the back >> branches. > > I was also wondering about the described behaviour. IMO > pg_size_pretty should handle negative values the same way as > positive values are handled. > +1 for me, thanks for the patch! > I've attached a patch which implements the requested behaviour. > The patch applies clean to HEAD (currently 85eda7e92). > I just reviewed your patch, everything looks fine for me. Maybe some minor cosmetic changes could be made to avoid declaring too many vars, but I think a committer would have a better idea on this, so I mark this patch as ready for committer. > AFAICS the documentation doesn't say anything about pg_size_pretty > and negative values. So, I didn't touch the documentation. If this > is a oversight by me or should be documented after all, I will > provide a additional documentation patch. > Yes, the documentation didn't say anything about the lack of formattting for negative value. I also don't think a patch is needed here. Regards. > Before the patch: > >> SELECT pg_size_pretty(size), pg_size_pretty(-1 * size) FROM >> (SELECT 100000000000000::bigint) foo(size); pg_size_pretty | >> pg_size_pretty ----------------+------------------------ 91 TB >> | -100000000000000 bytes (1 row) > >> SELECT pg_size_pretty(size), pg_size_pretty(-1 * size) FROM >> (SELECT 100000000000000::numeric) foo(size); pg_size_pretty | >> pg_size_pretty ----------------+------------------------ 91 TB >> | -100000000000000 bytes (1 row) > > After the patch: > >> SELECT pg_size_pretty(size), pg_size_pretty(-1 * size) FROM >> (SELECT 100000000000000::bigint) foo(size); pg_size_pretty | >> pg_size_pretty ----------------+---------------- 91 TB | >> -91 TB (1 row) > >> SELECT pg_size_pretty(size), pg_size_pretty(-1 * size) FROM >> (SELECT 100000000000000::numeric) foo(size); pg_size_pretty | >> pg_size_pretty ----------------+---------------- 91 TB | >> -91 TB (1 row) > > > The patch contains two tests (pg_size_pretty_bigint and > pg_size_pretty_numeric), to verify that positive and negative > values return the same result (except sign). > > Greetings, > > - Adrian > -- Julien Rouhaud http://dalibo.com - http://dalibo.org -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers