Ask a Question
Report a Bug
This page in other versions:
This document in other formats:
Use the Function dialog to define a function. If you drop and then recreate a function, the new function is not the same entity as the old; you must drop existing rules, views, triggers, etc. that refer to the old function.
The Function dialog organizes the development of a function through the following dialog tabs: General, Definition, Options, Arguments, Parameters, and Security. The SQL tab displays the SQL code generated by dialog selections.
Use the fields in the General tab to identify a function:
Click the Definition tab to continue.
Use the fields in the Definition tab to define the function:
Click the Options tab to continue.
Use the fields in the Options tab to describe or modify the action of the function:
Use the drop-down listbox next to Volatility to select one of the following. VOLATILE is the default value.
VOLATILE indicates that the function value can change even within a single table scan, so no optimizations can be made.
STABLE indicates that the function cannot modify the database, and that within a single table scan it will consistently return the same result for the same argument values.
IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same argument values.
Move the Returns a Set? switch to indicate if the function returns a set that includes multiple rows. The default is No.
Move the Strict? switch to indicate if the function always returns NULL whenever any of its arguments are NULL. If Yes, the function is not executed when there are NULL arguments; instead a NULL result is assumed automatically. The default is No.
Move the Security of definer? switch to specify that the function is to be executed with the privileges of the user that created it. The default is No.
Move the Window? switch to indicate that the function is a window function rather than a plain function. The default is No. This is currently only useful for functions written in C. The WINDOW attribute cannot be changed when replacing an existing function definition. For more information about the CREATE FUNCTION command, see the PostgreSQL core documentation available at:
Use the Estimated cost field to specify a positive number representing the estimated execution cost for the function, in units of cpu_operator_cost. If the function returns a set, this is the cost per returned row.
Use the Estimated rows field to specify a positive number giving the estimated number of rows that the query planner should expect the function to return. This is only allowed when the function is declared to return a set. The default assumption is 1000 rows.
Move the Leak proof? switch to indicate whether the function has side effects. The default is No. This option can only be set by the superuser.
Click the Arguments tab to continue.
Use the fields in the Arguments tab to define an argument. Click the Add icon (+) to set parameters and values for the argument:
Click the Add icon (+) to define another argument; to discard an argument, click the trash icon to the left of the row and confirm deletion in the Delete Row popup.
Click the Parameters tab to continue.
Use the fields in the Parameters tab to specify settings that will be applied when the function is invoked. Click the Add icon (+) to add a Name/Value field in the table.
Click the Security tab to continue.
Use the Security tab to assign privileges and define security labels.
Use the Privileges panel to assign usage privileges for the function to a role.
Click the Add icon (+) to assign additional privileges; to discard a privilege, click the trash icon to the left of the row and confirm deletion in the Delete Row popup.
Use the Security Labels panel to define security labels applied to the function. Click the Add icon (+) to add each security label selection:
Click the Add icon (+) to assign additional security labels; to discard a security label, click the trash icon to the left of the row and confirm deletion in the Delete Row popup.
Click the SQL tab to continue.
Your entries in the Function dialog generate a generate a SQL command (see an example below). Use the SQL tab for review; revisit or switch tabs to make any changes to the SQL command.
The following is an example of the sql command generated by selections made in the Function dialog:
The example demonstrates creating an edbspl function named emp_comp. The function adds two columns (p_sal and p_comm), and then uses the result to compute a yearly salary, returning a NUMERIC value.