From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Darafei "Komяpa" Praliaskouski <me@komzpa.net>
Cc: Nikita Glukhov <n.gluhov@postgrespro.ru>
Cc: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Cast jsonb to numeric, int, float, bool
Date: Wed, 28 Mar 2018 11:33:49 +0900
Message-ID: <20180328023349.GI1105@paquier.xyz> (raw)
In-Reply-To: <8775.1520873000@sss.pgh.pa.us>
References: <0154d35a-24ae-f063-5273-9ffcdf1c7f2e@postgrespro.ru>
<9c013081-5dc0-1b87-a559-a0c2d405727a@postgrespro.ru>
<151985418868.6915.17223208131889314092.pgcf@coridan.postgresql.org>
<76b000ae-94d1-cd8f-a2e0-e536096469b0@postgrespro.ru>
<CAC8Q8t+LDe9XMohGVnhNE3GgFhsVMJ38JvEVNf1DG1tg=mGD5Q@mail.gmail.com>
<af9cb89f-390e-9dce-74cf-f50371116847@postgrespro.ru>
<29252.1520866819@sss.pgh.pa.us>
<CAC8Q8t++bOLPHqb1ui5Gg+w0vuhEoAg7B__1XpgT8xzi4MF2sA@mail.gmail.com>
<8775.1520873000@sss.pgh.pa.us>
On Mon, Mar 12, 2018 at 12:43:20PM -0400, Tom Lane wrote:
> Another fundamental problem is that implicit casts mask mistakes.
> If there's an implicit cast to numeric, that applies everywhere not
> only where it was what you meant. For some context on this you might
> go back to the archives around the time of 8.3, where we actually
> removed a bunch of implicit casts because they led to too many
> surprising behaviors. Restricting implicit casts to the same type
> category is a rule-of-thumb for reducing the potential surprise
> factor.
+1 to that.
>> What would be other options, if not implicit cast?
>
> Explicit casts, ie (jsonvar->'fieldname')::numeric. Yeah, you have
> to write a bit more, but you don't get surprised by the way the
> parser interpreted your query.
>
> The other thing you can potentially do is use a variant operator
> name, as we did for text output with ->>. But that doesn't scale
> to very many result types, because it's impossible to choose
> readily mnemonic operator names. So I'd stick with the casts.
And +1 to that. Implicit casts are cool things when they don't cause a
potential loss of precision, which could be equivalent to losing some
data, so sticking with casts looks more acceptable to me, and I would
vote to not move on with this patch.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, me@komzpa.net, n.gluhov@postgrespro.ru, a.lubennikova@postgrespro.ru, pgsql-hackers@lists.postgresql.org
Subject: Re: Cast jsonb to numeric, int, float, bool
In-Reply-To: <20180328023349.GI1105@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox