pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Steele <david@pgmasters.net>
To: Nikita Glukhov <n.gluhov@postgrespro.ru>
To: Darafei Praliaskouski <me@komzpa.net>
To: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Re: Cast jsonb to numeric, int, float, bool
Date: Thu, 1 Mar 2018 09:13:48 -0500
Message-ID: <d75ed4fe-574b-41c7-080f-ed662fa5d9ba@pgmasters.net> (raw)
In-Reply-To: <76b000ae-94d1-cd8f-a2e0-e536096469b0@postgrespro.ru>
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>

On 2/28/18 7:12 PM, Nikita Glukhov wrote:
> On 01.03.2018 00:43, Darafei Praliaskouski wrote:
>>
>> The new status of this patch is: Ready for Committer
> 
> Attached new version of the patch in which I removed duplicated code
> using new subroutine JsonbExtractScalar(). I am not sure what is better
> to do when a JSON item has an unexpected type: to throw an error or to
> return SQL NULL. Also JSON nulls could be converted to SQL NULLs. I
> should note here that expression (jb -> 'key')::datatype can be
> rewritten with SQL/JSON function JSON_VALUE: JSON_VALUE(jb, '$.key'
> RETURNING datatype ERROR ON ERROR) But by standard JSON_VALUE tries to
> cast string JSON items to the specified datatype too, so
> JSON_VALUE('{"key": "123"}'::jsonb, '$.key' RETURNING int ERROR ON
> ERROR) does not throw an error but returns 123. We already have jsonpath
> operators @#, @*, so it might be very useful if our jsonb casts were
> equivalent to theirs SQL/JSON analogues. For example, (jb @#
> '$.key')::datatype could be equivalent to JSON_VALUE(jb, '$.key'
> RETURNING datatype ERROR ON ERROR) or JSON_VALUE(jb, '$.key' RETURNING
> datatype [NULL ON ERROR]). But if we want to have NULL ON ERRORbehavior
> (which is default in SQL/JSON) in casts, then casts should not throw any
> errors.

Since this patch was updated after being set a Ready for Committer and
there appear to be some open questions, I have set it to Needs Review.

Thanks,
-- 
-David
david@pgmasters.net




view thread (31+ messages)  latest in thread

Message-ID: <d75ed4fe-574b-41c7-080f-ed662fa5d9ba@pgmasters.net>
Permalink:  ../d75ed4fe-574b-41c7-080f-ed662fa5d9ba@pgmasters.net/
Also on:    postgresql.org/message-id/d75ed4fe-574b-41c7-080f-ed662fa5d9ba@pgmasters.net

 · 

reply

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: david@pgmasters.net, n.gluhov@postgrespro.ru, me@komzpa.net, a.lubennikova@postgrespro.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Re: Cast jsonb to numeric, int, float, bool
  In-Reply-To: <d75ed4fe-574b-41c7-080f-ed662fa5d9ba@pgmasters.net>

* 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