Re: BUG #15940: json_populate_recordset fails with ERROR: record typehas not been registered - Mailing list pgsql-bugs

From Dmitry Dolgov
Subject Re: BUG #15940: json_populate_recordset fails with ERROR: record typehas not been registered
Date
Msg-id CA+q6zcVYyjDEh9hkKi3eG81TBghMRjVySNA4gAsQU0q4gJPbFQ@mail.gmail.com
Whole thread Raw
In response to Re: BUG #15940: json_populate_recordset fails with ERROR: recordtype has not been registered  (Michael Paquier <michael@paquier.xyz>)
Responses Re: BUG #15940: json_populate_recordset fails with ERROR: record type has not been registered  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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))



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #15940: json_populate_recordset fails with ERROR: recordtype has not been registered
Next
From: Tom Lane
Date:
Subject: Re: BUG #15940: json_populate_recordset fails with ERROR: record type has not been registered