Re: BUG #15940: json_populate_recordset fails with ERROR: record type has not been registered
Dmitry Dolgov <9erthalion6@gmail.com>
From: Dmitry Dolgov <9erthalion6@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: yarexeray@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2019-08-06T11:34:51Z
Lists: pgsql-bugs
> On Tue, Aug 6, 2019 at 9:32 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Tue, Aug 06, 2019 at 06:41:34AM +0000, PG Bug reporting form wrote:
> > Following query works fine in previous freebsd versions
> >
> > SELECT
> > id_item
> > FROM json_populate_recordset(null::record, '[{"id_item":776}]')
> > AS
> > (
> > id_item int
> > );
>
> This visibly is a regression between 11 and 10, and one bisect later
> here is the culprit:
> commit: 37a795a60b4f4b1def11c615525ec5e0e9449e05
> author: Tom Lane <tgl@sss.pgh.pa.us>
> date: Thu, 26 Oct 2017 13:47:45 -0400
> Support domains over composite types.
Looks like there are tests for such behaviour with exactly this error, is there
a chance it was a feature? But anyway before this change there was an
invocation of get_call_result_type in the branch
if (have_record_arg && PG_ARGISNULL(0))
Adding similar stuff to the current implementation make this error to disappear
for me and passes tests (except those where we actually expect this error):
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -3647,7 +3647,19 @@ populate_recordset_worker(FunctionCallInfo
fcinfo, const char *funcname,
}
}
else
+ {
+ TupleDesc tupdesc;
+
rec = NULL;
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("function returning record called in context "
+ "that cannot accept type record")));
+
+ cache->c.io.composite.base_typid = tupdesc->tdtypeid;
+ cache->c.io.composite.base_typmod = tupdesc->tdtypmod;
+ }
/* if the json is null send back an empty set */
if (PG_ARGISNULL(json_arg_num))
Commits
-
Restore json{b}_populate_record{set}'s ability to take type info from AS.
- e136a0d8ca31 13.0 landed
- cdc8d371e27d 12.0 landed
- 2b24cf91a8e2 11.6 landed
-
Support domains over composite types.
- 37a795a60b4f 11.0 cited