Database Reference
In-Depth Information
RETURN helloworld;
END;
$$ LANGUAGE 'plpgsql';
The result can be seen using the following statement:
warehouse_db=# SELECT func_declare();
func_declare
--------------------
PostgreSQL rocks !
(1 row)
Declaring function parameters
Functions can accept and return values called function parameters or arguments .
These parameters should be declared before usage.
Parameters thus passed to functions are labeled with the numeric identiiers $1 and
$2 . We can also use an alias for a parameter name; both can then be later used to
reference the parameter value.
You can explicitly declare an alias as well, as shown in the following statement:
name ALIAS FOR $n;
A more detailed explanation of the preceding statement is as follows:
CREATE OR REPLACE FUNCTION alias_explain(int)
RETURNS integer AS $$
DECLARE
total ALIAS FOR $1;
BEGIN
RETURN total*10;
END;
$$ LANGUAGE plpgsql;
The more common format is the one where you give a name to the parameter in the
CREATE FUNCTION command, shown as follows:
CREATE OR REPLACE FUNCTION alias_explain( total int )
RETURNS integer AS $$
BEGIN
RETURN total*10;
END;
$$ LANGUAGE plpgsql;
 
Search WWH ::




Custom Search