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

From: ilmari(at)ilmari(dot)org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=)
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>, Darafei Praliaskouski <me(at)komzpa(dot)net>, Anastasia Lubennikova <a(dot)lubennikova(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Cast jsonb to numeric, int, float, bool
Date: 2018-03-30 15:21:26
Message-ID: d8j1sg1mvwp.fsf@dalvik.ping.uio.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2018-03-30 15:45:43 Re: pgsql: Rewrite the code that applies scan/join targets to paths.
Previous Message Peter Eisentraut 2018-03-30 15:16:08 Re: Feature Request - DDL deployment with logical replication