I want to make a Function in postgreSQL that reads the result of a query with a cursor and returns the result in a table. I am not very familiar with cursors but I have make an effort with no result. The output was a blank table. Here is my code:
CREATE OR REPLACE FUNCTION getquery()
RETURNS TABLE(ID INT, Totalprice DECIMAL) AS $$
DECLARE
query_cursor CURSOR FOR SELECT CustomerID, TotalDue from SalesOrderHeader where TotalDue =( select max(TotalDue) from SalesOrderHeader);
BEGIN
OPEN query_cursor;
CLOSE query_cursor;
RETURN;
END;$$
LANGUAGE plpgsql;