Re: Cast jsonb to numeric, int, float, bool

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

From: ilmari@ilmari.org (Dagfinn Ilmari Mannsåker )
To: Aleksander Alekseev <a.alekseev@postgrespro.ru>
Cc: Teodor Sigaev <teodor@sigaev.ru>, Robert Haas <robertmhaas@gmail.com>, David Steele <david@pgmasters.net>, Nikita Glukhov <n.gluhov@postgrespro.ru>, Darafei Praliaskouski <me@komzpa.net>, Anastasia Lubennikova <a.lubennikova@postgrespro.ru>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-03-30T15:21:26Z
Lists: pgsql-hackers
Aleksander Alekseev <a.alekseev@postgrespro.ru> writes:

> Hello Teodor,
>
>> > Agree, something like "could not convert jsonb value to boolean type. jsonb
>> > value must be scalar boolean type"?
>> 
>> I checked what error messages are used currently:
>> 
>> ```
>> # select 123::int4::jsonb;
>> ERROR:  cannot cast type integer to jsonb
>> LINE 1: select 123::int4::jsonb;
>> ```
>> 
>> I suggest to follow the same template, i.e. "cannot cast type jsonb to
>> bool", etc.
>
> On second thought this message is misleading. We can cat jsonb to bool,
> the problem is that the document is not a bool value.

How about "cannot cast jsonb $json_type to $sql_type" where $json_type
is the type inside the jsonb (e.g. string, number, boolean, array,
object)?

- ilmari
-- 
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
 the consequences of."                              -- Skud's Meta-Law


Commits

  1. Add casts from jsonb