Database Reference
In-Depth Information
The result of the preceding formats can be seen using the following statement:
warehouse_db=# SELECT alias_explain(10);
alias_explain
---------------
100
(1 row)
We have seen how to alias a parameter; now let's see the types of parameters. They
are IN , OUT , and INOUT . A function declared with the IN parameters contains a value
that can be passed to a function.
Remember that if not mentioned explicitly, function
parameters are IN by default.
The OUT parameters are the ones that get returned as the result. They are effective
when you have to return lots of output from a function without declaring the
PostgreSQL type as output of the function.
You can use the RETURNS statement in the CREATE FUNCTION
statement with the OUT parameters but this would be redundant.
A function that is declared with the INOUT parameters serves both purposes—they
can be passed in as well as processed and returned.
Let's look at the following function that explains the IN and OUT parameters:
warehouse_db=# CREATE OR REPLACE FUNCTION func_param( a int, IN b
int, OUT plus int, OUT sub int ) AS $$
BEGIN
plus := a + b;
sub := a - b;
END;
$$ LANGUAGE plpgsql;
The result can be seen using the following statement:
warehouse_db=# SELECT func_param(10, 5);
func_param
------------
(15,5)
(1 row)
 
Search WWH ::




Custom Search