<div>I'll be happy to drop result (the procedure created to insert logs). But this does not work too.<br /> <div style="background-color:#2f2f2f;padding:0px 0px 0px 2px"><div style="background-color:#2f2f2f;color:#cccccc;font-family:'cascadia code';font-size:11pt;white-space:pre"><p style="margin:0"><strong style="color:#739eca;font-weight:bold">CREATE</strong> <strong style="color:#739eca;font-weight:bold">OR</strong> <strong style="color:#739eca;font-weight:bold">REPLACE</strong> <strong style="color:#739eca;font-weight:bold">PROCEDURE</strong> <span style="color:#b788d3">public</span>.<span style="color:#b788d3">autonomous</span> (<span style="color:#00b8b8">p_script</span> <strong style="color:#739eca;font-weight:bold">IN</strong> <strong style="color:#c1aa6c;font-weight:bold">text</strong>)</p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">LANGUAGE</strong> <span style="color:#9e9e9e">plpgsql</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">AS</strong> <strong style="color:#eecc64;font-weight:bold">$autonomous$</strong></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">DECLARE</strong></p><p style="margin:0"><span style="color:#9e9e9e">l_id</span> <strong style="color:#c1aa6c;font-weight:bold">integer</strong><span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">BEGIN</strong></p><p style="margin:0"><span style="color:#9e9e9e">l_id</span> := <span style="color:#9e9e9e">pg_background_launch</span>(<span style="color:#9e9e9e">p_script</span>)<span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">PERFORM</strong> <span style="color:#9e9e9e">pg_background_result</span>(<span style="color:#9e9e9e">l_id</span>)<span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">END</strong><span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#eecc64;font-weight:bold">$autonomous$</strong><span style="color:#eecc64">;</span></p></div></div></div><div><br /></div><div><br /></div><div>----------------</div>
<div>Кому: Олег Самойлов (splarv(at)ya(dot)ru);<br /></div>
<div>Копия: pgsql-general(at)lists(dot)postgresql(dot)org;<br /></div>
<div>Тема: How to return seto records from seof record function?;<br /></div>
<div>25.02.2025, 17:29, "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>:<br /></div>
<blockquote>On Tuesday, February 25, 2025, Олег Самойлов <<a href="mailto:splarv(at)ya(dot)ru">splarv(at)ya(dot)ru</a>> wrote:<br /><blockquote class="f13ca48719c8a60033905b23b39675agmail_quote" style="border-left-color:#ccc;border-left-style:solid;border-left-width:1px;margin:0 0 0 0.8ex;padding-left:1ex"><div>Postgresql 17.2<br /><br />How to return seto records from seof record function? I tried pg_background extension:</div><div> </div><div><div style="background-color:#2f2f2f;padding:0px 0px 0px 2px"><div style="background-color:#2f2f2f;color:#cccccc;font-family:'cascadia code';font-size:11pt;white-space:pre-wrap"><p style="margin:0"><strong style="color:#739eca;font-weight:bold">CREATE</strong> <strong style="color:#739eca;font-weight:bold">OR</strong> <strong style="color:#739eca;font-weight:bold">REPLACE</strong> <strong style="color:#739eca;font-weight:bold">FUNCTION</strong> <span style="color:#b788d3">public</span>.<span style="color:#b788d3">autonomous</span> (<span style="color:#00b8b8">p_script</span> <strong style="color:#c1aa6c;font-weight:bold">text</strong>)</p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">RETURNS</strong> <strong style="color:#739eca;font-weight:bold">SETOF</strong> <span style="color:#9e9e9e">record</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">LANGUAGE</strong> <span style="color:#9e9e9e">plpgsql</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">VOLATILE</strong> <strong style="color:#739eca;font-weight:bold">STRICT</strong> <strong style="color:#739eca;font-weight:bold">PARALLEL</strong> <span style="color:#9e9e9e">UNSAFE</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">AS</strong> <strong style="color:#eecc64;font-weight:bold">$autonomous$</strong></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">DECLARE</strong></p><p style="margin:0"><span style="color:#9e9e9e">l_id</span> <strong style="color:#c1aa6c;font-weight:bold">integer</strong><span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">BEGIN</strong></p><p style="margin:0"><span style="color:#9e9e9e">l_id</span> := <span style="color:#9e9e9e">pg_background_launch</span>(<span style="color:#9e9e9e">p_script</span>)<span style="color:#eecc64"><wbr />;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">RETURN</strong> <span style="color:#9e9e9e">QUERY</span> <strong style="color:#739eca;font-weight:bold">SELECT</strong> * <strong style="color:#739eca;font-weight:bold">FROM</strong> <span style="color:#9e9e9e">pg_background_result</span>(<span style="color:#9e9e9e">l_id</span>) <strong style="color:#739eca;font-weight:bold">AS</strong> (<span style="color:#9e9e9e">r</span> <span style="color:#9e9e9e">record</span>)<span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#739eca;font-weight:bold">END</strong><span style="color:#eecc64">;</span></p><p style="margin:0"><strong style="color:#eecc64;font-weight:bold">$autonomous$</strong><span style="color:#eecc64">;</span></p><p style="margin:0"> </p><p style="margin:0"><u style="color:#739eca;font-weight:bold;text-decoration:underline #ff0080 wavy">SELECT</u><u style="text-decoration:underline #ff0080 wavy"> * </u><u style="color:#739eca;font-weight:bold;text-decoration:underline #ff0080 wavy">FROM</u><u style="text-decoration:underline #ff0080 wavy"> </u><u style="color:#9e9e9e;text-decoration:underline #ff0080 wavy">autonomous</u><u style="text-decoration:underline #ff0080 wavy">(</u><u style="color:#cac580;font-weight:bold;text-decoration:underline #ff0080 wavy">'SELECT now()'</u><u style="text-decoration:underline #ff0080 wavy">) </u><u style="color:#739eca;font-weight:bold;text-decoration:underline #ff0080 wavy">AS</u><u style="text-decoration:underline #ff0080 wavy"> (</u><u style="color:#9e9e9e;text-decoration:underline #ff0080 wavy">a</u><u style="text-decoration:underline #ff0080 wavy"> </u><u style="color:#c1aa6c;font-weight:bold;text-decoration:underline #ff0080 wavy">timestamptz</u><u style="text-decoration:underline #ff0080 wavy">)</u><u style="color:#eecc64;text-decoration:underline #ff0080 wavy">;</u></p><p style="margin:0"> </p><div>SQL Error [42804]: ERROR: structure of query does not match function result type</div><div> Detail: Returned type record does not match expected type timestamp with time zone in column 1.</div><div> Where: SQL statement "SELECT * FROM pg_background_result(l_id) AS (r record)"<span style="background-color:rgb( 255 , 255 , 255 );font-family:'helvetica neue' , 'helvetica' , 'arial' , sans-serif;font-size:15px"> </span></div></div></div></div></blockquote><blockquote class="f13ca48719c8a60033905b23b39675agmail_quote" style="border-left-color:#ccc;border-left-style:solid;border-left-width:1px;margin:0 0 0 0.8ex;padding-left:1ex"><div><div style="background-color:#2f2f2f;padding:0px 0px 0px 2px"><div style="background-color:#2f2f2f;color:#cccccc;font-family:'cascadia code';font-size:11pt;white-space:pre-wrap"><div>PL/pgSQL function autonomous(text) line 6 at RETURN QUERY</div></div></div></div></blockquote><div><br /></div><div>Interesting…not sure this can work as you have no way to know what the caller has specified as the return data type in order to write the inner generic function call correctly. Maybe you can convert the record result to jsonb and return that?</div><div><br /></div><div>David J.</div><div> </div>
</blockquote>