title: How to return a value inside a postgreSQL PL/pgSQL EXECUTE
body: <p>I am trying to return the insert id from within EXECUTE. This works fine:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.mytest2()
      RETURNS INTEGER
  LANGUAGE plpgsql
  AS $function$
  DECLARE
      retval  INTEGER;
      RETURNING "DULid" INTO retval;';
  BEGIN
      INSERT INTO "dbUpdateLog" (notes) VALUES ($$hello$$) RETURNING "DULid" INTO retval;
      RETURN retval;
  END;
  $function$
  </code></pre>
  
  <p>However, when doing it inside EXECUTE I get an error:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.mytest2()
      RETURNS INTEGER
  LANGUAGE plpgsql
  AS $function$
  DECLARE
      retval  INTEGER;
  BEGIN
      EXECUTE 'INSERT INTO "dbUpdateLog" (notes) VALUES ($$hello$$) RETURNING "DULid" INTO retval;';
      RETURN retval;
  END;
  $function$
  </code></pre>
  
  <p>I need to use EXECUTE as the queries will be dynamically generated. This is the error:</p>
  
  <pre><code>ERROR:  syntax error at or near "INTO"
  LINE 1: ...Log" (notes) VALUES ($$hello$$) RETURNING "DULid" INTO retva...
  </code></pre>
  
  <p>How can I get a return value (specifically the insert ID in this case) when used inside EXECUTE?</p>