title: Postgresql: Is there a way to return both table data and output parameters from a stored procedure as in Microsoft SQL Server
body: <p>In Microsoft Sql Server, both output parameters and select results can be used in cohesion to return data back to the client. This comes handy in use-cases like paging, where you need to return a main set along with associated meta-data like total page count. All the examples I have seen so far in Postgres either return data via output parameters or via table results. I am unable to create a procedure with both together as it fails with the following error:
  <strong>ERROR:  OUT and INOUT arguments aren't allowed in TABLE functions</strong></p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION fn_Test(out p_count int)
  RETURNS TABLE (CustomerId int, CustomerName varchar(50))
  LANGUAGE 'plpgsql'
  AS $BODY$
  BEGIN
  
      INSERT INTO Customers(CustomerName, Address, Area, Phonenumber, Email, communicationpreference)
      VALUES ('Julie Yellow', 'JY Ad', 'JY Ar', 'JV0987654', 'j@ye.com', 1);
  
      SELECT COUNT(*) FROM CUSTOMERS INTO  p_count;
      SELECT CustomerId, CustomerName FROM Customers;
  EXCEPTION WHEN OTHERS THEN
      RAISE exception '% %', SQLERRM, SQLSTATE;
  END;
  $BODY$
  </code></pre>
  
  <p>Can't they go together? Is there any alternative approach in Postgresql?</p>
  
  <p>Please advice</p>