public inbox for [email protected]  
help / color / mirror / Atom feed
From: Олег Самойлов <[email protected]>
To: [email protected] <[email protected]>
Subject: How to return seto records from seof record function?
Date: Tue, 25 Feb 2025 17:15:15 +0300
Message-ID: <[email protected]> (raw)

<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"><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">;</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)"</div><div>PL/pgSQL function autonomous(text) line 6 at RETURN QUERY</div></div></div></div>

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: How to return seto records from seof record function?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox