$$
CREATE FUNCTION add(integer, integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
$$
// Create a function to add 2 integers (SQL)
This function takes 2 integers as parameters
IMMUTABLE
means that the function cannot modify the database and always returns the same result when given the same argument values
select add(5,9);
add
-----
14
(1 row)
// Function call (SQL)
\df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+---------------------+--------
public | add | integer | integer, integer | normal
(1 row)
// Display all Functions (psql)
\df+
// Display all Functions including addition information including owner, source code & description etc. (psql)
\ef myfunction
// Edit a function in default editor (psql)