Managing procedures and transactions
Once you have decided on a procedural language, it is time to get started with real work. The first important fact you have to keep in mind is that PostgreSQL relies heavily on an object-oriented feature called function overloading. This term means that various functions can have the same name but accept different input parameters.
One function may be called func(int, int)
, while some other function may be called func(text, text)
. Always keep in mind that the entire signature of the function is what counts:
test=# CREATE FUNCTION mysum(int, int) RETURNS int AS ' SELECT $1 + $2 ' LANGUAGE 'sql'; CREATE FUNCTION test=# CREATE FUNCTION mysum(text, text) RETURNS text AS ' SELECT $1 || $2 ' LANGUAGE 'sql'; CREATE FUNCTION
In this case, two functions have been defined. The first will take two integers, and the second takes two text values. Depending on how the function is called, different portions of code will be executed:
test=# SELECT mysum(10, 20...