Re: remaining sql/json patches

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: Re: remaining sql/json patches
Date: 2023-07-14 07:13:17
Message-ID: CA+HiwqFX9v8K9cZAVtfHeJYCQUicOoYrRGg67KBN_eN-fBEf0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Alvaro,

On Fri, Jul 14, 2023 at 1:54 AM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
> I looked at your 0001. My 0001 are some trivial comment cleanups to
> that.

Thanks.

> I scrolled through all of jsonfuncs.c to see if there was a better place
> for the new function than the end of the file. Man, is that one ugly
> file. There are almost no comments! I almost wish you would create a
> new file so that you don't have to put this new function in such bad
> company. But maybe it'll improve someday, so ... whatever.

I tried to put it somewhere that is not the end of the file, though
anywhere would have looked arbitrary anyway for the reasons you
mention, so I didn't after all.

> In the original code, the functions here being (re)moved do not need to
> return a type output function in a few cases. This works okay when the
> functions are each contained in a single file (because each function
> knows that the respective datum_to_json/datum_to_jsonb user of the
> returned values won't need the function OID in those other cases); but
> as an exported function, that strange API doesn't seem great. (It only
> works for 0002 because the only thing that the executor does with these
> cached values is call datum_to_json/b).

Agreed about not tying the new API too closely to datum_to_json[b]'s needs.

> That seems easy to solve, since
> we can return the hardcoded output function OID in those cases anyway.
> A possible complaint about this is that the OID so returned would be
> untested code, so they might be wrong and we'd never know. However,
> ISTM it's better to make a promise about always returning a function OID
> and later fixing any bogus function OID if we ever discover that we
> return one, rather than having to document in the function's comment
> that "we only return function OIDs in such and such cases". So I made
> this change my 0002.

+1

> A similar complaint can be made about which casts we look for. Right
> now, only an explicit cast to JSON is useful, so that's the only thing
> we do. But maybe one day a cast to JSONB would become useful if there's
> no cast to JSON for some datatype (in the is_jsonb case only?); and
> maybe another type of cast would be useful. However, that seems like
> going too much into uncharted territory with no useful use case, so
> let's just not go there for now. Maybe in the future we can improve
> this aspect of it, if need arises.

Hmm, yes, the note in the nearby comment stresses "to json (not to
jsonb)", though the (historical) reason why is not so clear to me.
I'm inclined to leave that as-is.

I've merged your deltas in the attached 0001 and rebased the other
patches. In 0002, I have now removed RETURNING support for JSON() and
JSON_SCALAR().

--
Thanks, Amit Langote
EDB: http://www.enterprisedb.com

Attachment Content-Type Size
v7-0001-Unify-JSON-categorize-type-API-and-export-for-ext.patch application/octet-stream 27.6 KB
v7-0002-SQL-JSON-functions.patch application/octet-stream 50.9 KB
v7-0004-JSON_TABLE.patch application/octet-stream 160.8 KB
v7-0005-Claim-SQL-standard-compliance-for-SQL-JSON-featur.patch application/octet-stream 2.3 KB
v7-0003-SQL-JSON-query-functions.patch application/octet-stream 209.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2023-07-14 07:34:33 Re: logical decoding and replication of sequences, take 2
Previous Message Melih Mutlu 2023-07-14 06:53:24 Re: Changing types of block and chunk sizes in memory contexts