[HACKERS] Cast jsonb to numeric, int, float, bool

Поиск
Список
Период
Сортировка
Искать
От
Anastasia Lubennikova
Тема
[HACKERS] Cast jsonb to numeric, int, float, bool
Дата
Msg-id
0154d35a-24ae-f063-5273-9ffcdf1c7f2e@postgrespro.ru
Список
Дерево обсуждения
[HACKERS] Cast jsonb to numeric, int, float, bool Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Re: [HACKERS] Cast jsonb to numeric, int, float, bool Nikita Glukhov <n.gluhov@postgrespro.ru>
Re: [HACKERS] Cast jsonb to numeric, int, float, bool Jim Nasby <Jim.Nasby@BlueTreble.com>
Re: [HACKERS] Cast jsonb to numeric, int, float, bool Nikita Glukhov <n.gluhov@postgrespro.ru>
Re: [HACKERS] Cast jsonb to numeric, int, float, bool Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool Darafei Praliaskouski <me@komzpa.net>
Re: Cast jsonb to numeric, int, float, bool Nikita Glukhov <n.gluhov@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool Darafei "Komяpa" Praliaskouski <me@komzpa.net>
Re: Cast jsonb to numeric, int, float, bool Nikita Glukhov <n.gluhov@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool Tom Lane <tgl@sss.pgh.pa.us>
Re: Cast jsonb to numeric, int, float, bool Darafei "Komяpa" Praliaskouski <me@komzpa.net>
Re: Cast jsonb to numeric, int, float, bool Tom Lane <tgl@sss.pgh.pa.us>
Re: Cast jsonb to numeric, int, float, bool Michael Paquier <michael@paquier.xyz>
Re: Cast jsonb to numeric, int, float, bool Darafei "Komяpa" Praliaskouski <me@komzpa.net>
Re: Re: Cast jsonb to numeric, int, float, bool David Steele <david@pgmasters.net>
Re: Re: Cast jsonb to numeric, int, float, bool Aleksander Alekseev <a.alekseev@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Robert Haas <robertmhaas@gmail.com>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Aleksander Alekseev <a.alekseev@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool Aleksander Alekseev <a.alekseev@postgrespro.ru>
Re: Cast jsonb to numeric, int, float, bool ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Re: Cast jsonb to numeric, int, float, bool Robert Haas <robertmhaas@gmail.com>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Tom Lane <tgl@sss.pgh.pa.us>
Re: Cast jsonb to numeric, int, float, bool Tom Lane <tgl@sss.pgh.pa.us>
Re: Cast jsonb to numeric, int, float, bool Teodor Sigaev <teodor@sigaev.ru>
Re: Cast jsonb to numeric, int, float, bool Tom Lane <tgl@sss.pgh.pa.us>
Re: Cast jsonb to numeric, int, float, bool Aleksander Alekseev <a.alekseev@postgrespro.ru>
Now the simplest way to extract booleans and numbers from json/jsonb is 
to cast it
to text and then cast to the appropriate type:

postgres=# select 'true'::jsonb::text::bool;
  bool
------
  t
postgres=# select '1.0'::jsonb::text::numeric;
  numeric
---------
      1.0


This patch implements direct casts from jsonb numeric (jbvNumeric) to 
numeric, int4 and float8,
and from jsonb bool (jbvBool) to bool.

postgres=# select 'true'::jsonb::bool;
  bool
------
  t

postgres=# select '1.0'::jsonb::numeric;
  numeric
---------
      1.0


Waiting for your feedback.
If you find it useful, I can also add support of json and other types, 
such as smallint and bigint.

-- 
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
В списке pgsql-hackers по дате отправления
От: Rafia Sabih
Дата:
От: Vik Fearing
Дата:
FAQ