Функция plpgsql с курсором.
CREATE FUNCTION select_all_from_users () RETURNS TABLE ( id INT, name VARCHAR, age INT, date_add timestamp ) AS $$ DECLARE users RECORD; BEGIN FOR users IN SELECT * FROM customers LOOP RETURN NEXT; END LOOP; END; $$ LANGUAGE plpgsql;