Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSicl-0003t6-21 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:23:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSicj-00080e-6k for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:23:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSici-00080K-Vk for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:23:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSicg-0000qj-Ah for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:23:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 09EFNKuT3602056; Wed, 14 Oct 2020 11:23:20 -0400 From: Tom Lane To: Magnus Hagander cc: Thomas Kellerer , pgsql-general Subject: Re: Parameter value from (mb/gb) to bytes In-reply-to: References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> Comments: In-reply-to Magnus Hagander message dated "Wed, 14 Oct 2020 17:16:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3602054.1602689000.1@sss.pgh.pa.us> Date: Wed, 14 Oct 2020 11:23:20 -0400 Message-ID: <3602055.1602689000@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Magnus Hagander writes: > On Wed, Oct 14, 2020 at 5:10 PM Tom Lane wrote: >> It's fairly annoying that this doesn't work: >> regression=# select pg_size_bytes(setting||' '||unit) from pg_settings >> where name = 'shared_buffers'; > Actually thinking though, surely *this* particular case can be spelled as: > SELECT pg_size_bytes(current_setting('shared_buffers')) Yeah, that might be the most recommendable way. > Or if doing it off pg_settings: > SELECT setting::bigint * pg_size_bytes(unit) from pg_settings where > name='shared_buffers' No, because that will fail for any unit other than '8kB', eg regression=# select pg_size_bytes('MB'); ERROR: invalid size: "MB" > I'm not sure having pg_size_bytes() parse "16384 8kB" is reasonable, I have > a feeling that could lead to a lot of accidental entries giving the wrong > results. Yeah, that's definitely a risk. Given that current_setting() already does what's needed, that's probably a better answer. regards, tom lane