commit c0cbe00fee6d0a5e0ec72c6d68a035e674edc4cc
Author: Teodor Sigaev <teodor@sigaev.ru>
Date: Thu Mar 29 16:33:56 2018 +0300
Add casts from jsonb
Add explicit cast from scalar jsonb to all numeric and bool types. It would be
better to have cast from scalar jsonb to text too but there is already a cast
from jsonb to text as just text representation of json. There is no way to have
two different casts for the same type's pair.
Bump catalog version
Author: Anastasia Lubennikova with editorization by Nikita Glukhov and me
Review by: Aleksander Alekseev, Nikita Glukhov, Darafei Praliaskouski
Discussion: https://www.postgresql.org/message-id/flat/0154d35a-24ae-f063-5273-9ffcdf1c7f2e@postgrespro.ru
=# select 'true' :: jsonb :: bool;
ERROR: cannot cast type jsonb to boolean
LINE 1: select 'true' :: jsonb :: bool;
=# select '12345' :: jsonb :: int4;
ERROR: cannot cast type jsonb to integer
LINE 1: select '12345' :: jsonb :: int4;
=# select '12345.67' :: jsonb :: float8;
ERROR: cannot cast type jsonb to double precision
LINE 1: select '12345.67' :: jsonb :: float8;
=# select '12345.67' :: jsonb :: text :: float8;
float8
----------
12345.67
=# select 'true' :: jsonb :: bool;
bool
------
t
=# select '12345' :: jsonb :: int4;
int4
-------
12345
=# select '12345.67' :: jsonb :: float8;
float8
----------
12345.67
=# select 12345.67 :: jsonb;
ERROR: cannot cast type numeric to jsonb
LINE 1: select 12345.67 :: jsonb;
=# select 12345.67 :: text :: jsonb;
jsonb
----------
12345.67
(1 row)
Source: https://habr.com/ru/post/358256/
All Articles