[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
обсуждение исходный текст
Ответы Re: [HACKERS] Cast jsonb to numeric, int, float, bool
Re: [HACKERS] Cast jsonb to numeric, int, float, bool
Список pgsql-hackers
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 по дате отправления: