Re: remaining sql/json patches

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
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-13 16:54:13
Message-ID: 20230713165413.kj6vawaslldf25hp@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I looked at your 0001. My 0001 are some trivial comment cleanups to

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.

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). 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.

A similar complain 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.

Álvaro Herrera Breisgau, Deutschland —

Attachment Content-Type Size
0001-trivial-fixups.notpatch text/plain 2.4 KB
0002-make-the-output-generally-usable-not-just-for-datum_.notpatch text/plain 2.3 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2023-07-13 17:01:44 Re: MERGE ... RETURNING
Previous Message Vik Fearing 2023-07-13 16:43:37 Re: MERGE ... RETURNING