|From:||Anastasia Lubennikova <a(dot)lubennikova(at)postgrespro(dot)ru>|
|Subject:||Re: [HACKERS] Cast jsonb to numeric, int, float, bool|
|Views:||Raw Message | Whole Thread | Download mbox | Resend email|
01.02.2017 17:41, Anastasia Lubennikova:
> 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;
> postgres=# select '1.0'::jsonb::text::numeric;
> 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;
> postgres=# select '1.0'::jsonb::numeric;
> Waiting for your feedback.
> If you find it useful, I can also add support of json and other types,
> such as smallint and bigint.
I totally forgot about this thread, but it is a small but useful feature.
Maybe it's time to dust it off.
This patch was made by request of one of our clients,
and though they already use custom build, I think it would be better to
have these casts in core.
The patch is attached.
There are no tests yet, since I don't really sure what set of types do
we want to support.
Now the patch provides jsonb to numeric, int4, float8 and bool.
Also I have some doubts about castcontext. But 'explisit' seems to be
the correct one here.
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
|Next Message||David Steele||2018-02-28 18:48:49||Re: [PATCH] Verify Checksums during Basebackups|
|Previous Message||Robert Haas||2018-02-28 18:11:16||Re: Server won't start with fallback setting by initdb.|