Re: Cast jsonb to numeric, int, float, bool - Mailing list pgsql-hackers

From Darafei "Komяpa" Praliaskouski
Subject Re: Cast jsonb to numeric, int, float, bool
Date
Msg-id CAC8Q8t++bOLPHqb1ui5Gg+w0vuhEoAg7B__1XpgT8xzi4MF2sA@mail.gmail.com
Whole thread Raw
In response to Re: Cast jsonb to numeric, int, float, bool  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Cast jsonb to numeric, int, float, bool  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi Tom,
 
I hadn't been following this thread particularly, but I happened to notice
this bit, and I thought I'd better pop up to say No Way.  There will be
*no* implicit casts from json to any numeric type.  We have learned the
hard way that implicit cross-category casts are dangerous. 

I can see how a cast from text can be problematic, especially before the 'unknown' type.

But what would be the scenario of failure if we have an implicit cast from jsonb datatype (that likely already parsed the number internally, or knows it holds non-numeric value) to numeric, that returns an error if it's unable to perform the conversion?

The issue I think is that jsonb is special because it is in fact container. We've got dot-notation to unpack things from composite TYPE, and we've got arrow-notation to unpack things from jsonb, but such unpacking cannot take part in further computations, even though it's visually compatible.

What would be other options, if not implicit cast?

Darafei Praliaskouski, 
GIS Engineer / Juno Minsk

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: JIT compiling with LLVM v11
Next
From: Nikita Glukhov
Date:
Subject: Re: Jsonb transform for pl/python