PostgreSQL provides four kinds of functions:
query language functions (functions written in SQL) (Section 34.4)
procedural language functions (functions written in, for example, PL/Tcl or PL/pgSQL) (Section 34.5)
internal functions (Section 34.6)
C-language functions (Section 34.7)
Every kind of function can take base types, composite types, or some combination as arguments (parameters). In addition, every kind of function can return a base type or a composite type.
It's easiest to define SQL functions, so we'll start with those. Examples in this section can also be found in funcs.sql and funcs.c in the tutorial directory.
Throughout this chapter, it can be useful to look at the reference page of the CREATE FUNCTION command to understand the examples better.