Re: Parameter value from (mb/gb) to bytes

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Re: Parameter value from (mb/gb) to bytes
Дата
Msg-id CABUevEwKawp+=y4v3tYPueL=y2nuVzn=17UeLM8crjmbTVrHwg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Parameter value from (mb/gb) to bytes  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Parameter value from (mb/gb) to bytes  (Raul Kaubi <raulkaubi@gmail.com>)
Список pgsql-general


On Wed, Oct 14, 2020 at 5:23 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Magnus Hagander <magnus@hagander.net> writes:
> On Wed, Oct 14, 2020 at 5:10 PM Tom Lane <tgl@sss.pgh.pa.us> 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"

Right, but it would certainly work for *this* case using pg_asettings, is what I meant.

That said, I think it'd then actually be better to teach pg_size_bytes to know that "MB" is the same as "1MB" and parse that. That might be something that would actually be useful in other cases as well -- basically as a way to get conversion units in general. Basically if the string is "unit only" then consider that as "1 unit".

--

В списке pgsql-general по дате отправления:

Предыдущее
От: Raul Kaubi
Дата:
Сообщение: Re: Parameter value from (mb/gb) to bytes
Следующее
От: Teodor Sigaev
Дата:
Сообщение: Re: rum index supported on pg13?