I seldom use
pgSQL, and mostly use it from .NET with the
NpgSQL driver, but here are some examples. Sadly I got no output displayed in the pgAdmin window, but saving the results to a file worked.
Simple example from
PostgreSQL wiki[
^]
--DROP FUNCTION getemployees();
create function GetEmployees() returns setof employee as 'select * from employee;' language 'sql';
select * from GetEmployees();
Here is a more elaborate example from
PL/pgSQL Declaration - w3resource[
^]
CREATE FUNCTION get_employee(text) RETURNS text AS '
DECLARE
frst_name ALIAS FOR $1;
lst_name employees.last_name%TYPE;
BEGIN
SELECT INTO lst_name last_name FROM employees
WHERE first_name = frst_name;
return frst_name || '' '' || lst_name;
END;
' LANGUAGE 'plpgsql';
And then call it like this:
SELECT get_employee('John');
You can also call your functions in
PgAdmin by right-clicking on them in the tree on the left and then use '
Scripts - Select Script', this way the output will be displayed in the output window.