title: Invoke Stored Procedure and Return ID
body: <p>I have a stored procedure that should do the following:</p>
  
  <ol>
  <li>Get next value from sequence </li>
  <li>Insert into a table </li>
  <li>Return ID of inserted (step 1)</li>
  </ol>
  
  <p>My stored procedure code is as below:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE insert_landed_trades_tp (timestamp without time zone, varchar(200), varchar(200), varchar(200), json) 
  LANGUAGE plpgsql
  AS $$
  
  DECLARE
      next_id bigint;
  BEGIN
  
      SELECT nextval('trades_landed_tp_row_id_seq') INTO next_id;
  
      INSERT INTO trades_landed_tp (row_id, capture_dt, trade_guid, feed_name, connector_name, payload, status_code)
      VALUES (next_id, $1, $2, $3, $4, $5, 1);
  
      COMMIT;
  
      SELECT next_id;
  
  END;
  $$;
  </code></pre>
  
  <p>I now want to call this stored procedure and consume the ID of the inserted record:</p>
  
  <pre><code>CALL insert_landed_trades_tp (timezone('utc'::text, now()), 'giud'::varchar(200), 'feed'::varchar(200),'connector'::varchar(200), '{ "customer": "John Doe", "items": {"product": "Beer","qty": 6}}'::json);
  </code></pre>
  
  <p>In PgAdmin, the above givees the following error:</p>
  
  <blockquote>
  <pre><code>ERROR:  query has no destination for result data
  HINT:  If you want to discard the results of a SELECT, use PERFORM instead
  </code></pre>
  </blockquote>
  
  <p>So, my questions are:</p>
  
  <ul>
  <li>How do I fix the code to achieve desired outcome?</li>
  <li>Could this be achieved more simply?</li>
  </ul>
  
  <p>Note that once stored procedure development is completed, the procedure would be called from an application (in Python or C#), not from PgAdmin.</p>