Re: JSON[B] arrays are second-class citizens

From: Peter van Hardenberg <pvh(at)pvh(dot)ca>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: JSON[B] arrays are second-class citizens
Date: 2016-06-01 00:04:14
Message-ID: CABTbUpjBTNRGse8=EAHwUbNXStK5ti+BJS9JW-N0qJO-UgM73g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The idea of converting a JSONB array to a PG array is appealing and would
potentially be more general-purpose than adding a new unnest. I'm not sure
how feasible either suggestion is.

I will say that I think the current state of affairs is gratuitously
verbose and expects users to memorize a substantial number of long function
names to perform simple tasks.

-p

On Tue, May 31, 2016 at 2:06 PM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Tue, May 31, 2016 at 4:34 PM, David Fetter <david(at)fetter(dot)org> wrote:
>
>> Folks,
>>
>> While querying some JSONB blobs at work in preparation for a massive
>> rework of the data infrastructure, I ran into things that really
>> puzzled me, to wit:
>>
>> SELECT * FROM unnest('["a","b","c"]'::jsonb);
>> ERROR: function unnest(jsonb) does not exist
>>
>> SELECT * FROM jsonb_array_elements('["a","b","c"]'::jsonb);
>> value
>> ───────
>> "a"
>> "b"
>> "c"
>> (3 rows)
>>
>>
> ​I'd be inclined to -1 such a proposal. TIMTOWTDI is not a principle that
> we endeavor to emulate.
>
> Having an overloaded form: <unnest(jsonb) : setof jsonb> is unappealing.
> While likely not that common the introduction of an ambiguity makes raises
> the bar considerably.
>
> That said we do seem to be lacking any easy way to take a json array and
> attempt to convert it directly into a PostgreSQL array. Just a conversion
> is not always going to succeed though the capability seems worthwhile if as
> yet unasked for. The each->convert->array_agg pattern works but is likely
> inefficient for homogeneous json array cases.
>
> David J.
>

--
Peter van Hardenberg
San Francisco, California
"Everything was beautiful, and nothing hurt."—Kurt Vonnegut

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-06-01 00:24:11 Re: COMMENT ON, psql and access methods
Previous Message Andreas Karlsson 2016-05-31 22:48:18 Re: Parallel safety tagging of extension functions