Creates a function for use in queries.
The function body must be written in a SQL or PL/pgSQL language. A PL/pgSQL function body must include the block syntax such as 'DECLARE', 'BEGIN' and 'END;'.
Note that functions are immutable and the function body must not contain any statements that would affect the database state.
Available in a network database and requires the star$define role.
Parameters:
| Name | Optional | Type | Description |
| function$ | Mandatory | Text | The name of the function being created. |
| arguments$ | Mandatory | Text | Argument specification required by the function. |
| return$ | Mandatory | Text | The return type of the function. |
| language$ | Mandatory | Text | The function language – either SQL or PLPGSQL. |
| body$ | Mandatory | Text | The body of the function. |
Examples:
SELECT create_function('mysqlfunc','arg1 int','int','sql','select arg1+1;'); -- creates a SQL function.
SELECT create_function('myplfunc','arg1 int','int','plpgsql','begin return arg1+1; end;'); -- creates a PL/pgSQL function.
Tips:
- The star$functions view indicates which functions already exist.
Comments
Article is closed for comments.