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: ERROR: OUT and INOUT arguments aren't allowed in TABLE functions
Here is what I tried:
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', '[email protected]', 1);
SELECT COUNT(*) FROM CUSTOMERS INTO p_count;
SELECT CustomerId, CustomerName FROM Customers;
EXCEPTION WHEN OTHERS THEN
RAISE exception '% %', SQLERRM, SQLSTATE;
END;
$BODY$
Can't they go together? Is there any alternative approach in Postgresql?
Please advice