Define PostgreSQL Functions
Use the PostgreSQL Function Editor to define a function for a database or table in a PostgreSQL physical model.
Although in the syntax of PostgreSQL function, the "External" option is available for Security of Definer property, this option is not available in the database. Hence, this option is also not available under Security of Definer property. Similarly, the CALLED ON NULL INPUT and RETURNS NULL ON NULL INPUT options too are unavailable on the PostgreSQL Function Editor.
To define a PostgreSQL function
- In the Model Explorer, right-click Functions and click New.
An instance of Function is created.
- Right-click the instance and click Properties. Alternatively, you can also click Functions on the Model menu.
The PostgreSQL Function Editor opens.
- In the navigation grid, select the function that you want to define and work with the following options:
Click New on the toolbar to create a function. Use the Enter filter text box to filter a very large list of functions to quickly locate the one that you want to define.
- Name
Specifies the name of the function. Set the name of the function in this field.
- Generate
Generates SQL during forward engineering. Clear the check box if you do not want to generate SQL.
- On the PostgreSQL tab, work with the following options:
- Schema
Specifies the schema for the function. Select a schema from the drop-down list or click New to create one.
- Owner
Specifies the owner of the function. Select a role from the drop-down list or click New and create one.
- Language
Specifies the name of the language that the function is implemented in. It can be SQL, C, internal, or the name of a user-defined procedural language, for example plpgsql.
- Window Function
Indicates that the function is a window function rather than a plain function. This is currently only useful for functions written in C.
- Volatility
Informs the query optimizer about the behavior of the function. Select one of the following:
- Immutable
Indicates that the function cannot modify the database and always returns the same result when given the same argument values. That is, it does not do database lookups or otherwise use information not directly present in its argument list.
- 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, but that its result could change across SQL statements.
- Volatile
Indicates that the function value can change even within a single table scan, so no optimizations can be made. Relatively few database functions are volatile in this sense; some examples are random(), currval(), timeofday().
- Strict
Indicates that the function always returns null whenever any of its arguments are null. If this parameter is specified, the function is not executed when there are null arguments; instead a null result is assumed automatically.
- Leak Proof
Indicates that the function has no side effects. It reveals no information about its arguments other than by its return value.
- Estimated Cost
Specifies a positive number giving 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. If the cost is not specified, 1 unit is assumed for C-language and internal functions, and 100 units for functions in all other languages.
- Returns Set
Indicates that the function will return a set of items, rather than a single item.
- Estimated Rows
Specifies a positive number giving the estimated number of rows that the 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.
- Security Of Definer
Specifies the privilege that is to be used to execute the function. Select one of the following:
- Security Invoker
Indicates that the function is to be executed with the privileges of the user that calls it. That is the default.
- Security Definer
Specifies that the function is to be executed with the privileges of the user that created it.
- Parallel
Specifies the mode of execution of the function. Select one of the following:
- Unsafe
Indicates that the function can not be executed in parallel mode. The presence of such a function in an SQL statement forces a serial execution plan. This is the default.
- Restricted
Indicates that the function can be executed in parallel mode, but the execution is restricted to parallel group leader.
- Safe
Indicates that the function is safe to run in parallel mode without restriction.
- Object File
Specifies the name of the file containing the dynamically loadable object for C language functions.
- Link Symbol
Specifies the function's link symbol, that is, the name of the function in the C language source code. If the link symbol is omitted, it is assumed to be the same as the name of the SQL function being defined.
- Function Type
Specifies the type of the function. Select one of the following:
- Scalar
Indicates that the default return type will be used and all the parameters will be emitted.
- Table
Specifies that the return definition of the function is a table, using this option will only emit IN parameters in the arguments.
- Trigger
Specifies that the defined function is a trigger function.
- Return Data Type
Specifies the return data type of the function.
- Return Table Definition
Specify the referenced table.
- Click the Parameters tab and click New on the toolbar to create a parameter. Then, work with the following options:
- Parameters
Specifies the name of the parameter.
- Physical Data Type
Specifies the return data type of the parameter.
- Type
Specifies the type of the parameter. Select one out of IN, OUT, IN OUT, and VARIADIC.
- Default Value
Specifies an expression to be used as default value if the parameter is not specified. The expression has to be coercible to the argument type of the parameter. Only input (including IN OUT) parameters can have a default value.
- Click the Variables tab and click New on the toolbar to create a variable. Then, work with the following options:
- Variables
Specifies the name of the variable.
- Variable Value
Specifies an expression to be used as the variable value.
- Work with the other tabs in the editor to access additional design features, for example:
- Define the code type in the Code tab.
- View expanded code in the Expanded tab.
- Define function permissions using the Permission tab.
- Specify the order of DDL generation in the Object Creation Order tab.
- (Optional) Click the Comment tab and enter any comments that you want to associate with the object.
- (Optional) Click the Where Used tab to view where the object is used within the model.
- (Optional) Click the UDPtab to work with user-defined properties for the object.
- (Optional) Click the Notestab to view and edit user notes.
- (Optional) Click the Extended Notes tab to view or edit user notes.
- Click Close.
The function is defined and the PostgreSQL Function Editor closes.
For more information, refer to PostgreSQL documentation.
Copyright © 2024 Quest Software, Inc. |