Defining PostgreSQL Functions

The following properties are applicable to a PostgreSQL Function object.

Tab

Section

Property

Description

Additional Information

 

 

Name

Specifies the name of the function

 

 

 

Use Replace Syntax

Specifies whether the REPLACE syntax is used

Selecting this option replaces the syntax with the new DDL that is generated during Forward Engineering

 

 

Schema

Specifies the schema for the function

 

 

 

Generate

Specifies whether a SQL statement for the collation is generated during forward engineering

 

General

Function Options

Language

Specifies the name of the language in which the function is implemented

Internal, c, Sql, User Defined: Specifies procedural languages of the function

Transform

Lists which transforms a call to the function should apply. Transforms convert between SQL types and language-specific data types

 

Is Window

Indicates that the function is a window function rather than a plain function, which is currently only useful for functions written in C

 

Volatility

Informs the query optimizer about the behavior of the function

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 within a single table scan, preventing any optimizations. Relatively few database functions are volatile in this sense; examples include random(), currval(), and timeofday().

Leak Proof

Indicates that the function has no side effects. It reveals no information about its arguments other than by its return value

LEAKPROOF: Indicates that the function has no side effects. It reveals no information about its arguments other than by its return value.

NOT LEAKPROOF: A function that might throw an error based on the values received as arguments (such as one that throws an error due to overflow or division by zero) is not leak-proof and could reveal significant information about unseen rows if applied before the security view's row filters.

Null_Input_Type

 

Called on null input: Indicates that the function is called correctly even when some parameters are null. Function authors must check for null values and respond appropriately.

Returns null on null input or Strict: Specifies that the method returns null when any parameters are null. When this option is set, the function is not performed with null parameters, and a null result is presumed.

Security_Type

Specifies the privilege that is to be used to execute the function

Definer: Specifies that the function is to be executed with the privileges of the user that owns it.

Invoker: indicates that the function is to be executed with the privileges of the user that calls it.

External

This is optional for SQL conformance, as it applies to all functions, not just external ones.

 

Parallel

Specifies the mode of execution of the function

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.

Safe: Indicates that the function can run in parallel mode without restriction.

Restricted: Indicates that the function can be executed in parallel mode, but the execution is restricted to parallel group leader.

Execution 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.

 

Result Row

Specifies a positive number indicating the estimated rows the planner should expect the function to return when it returns a set. The default is 1000 rows.

 

Support Function

Specifies the name (optionally schema-qualified) of a planner support function to use for this function

Ensure that you have a superuser role to use this function.

As Function Definition

Defines the function's meaning and can be an internal function name, object file location, SQL command, or procedural text. Dollar quoting is useful for syntax.

 

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, which is the name of the function in the C language source code. If you omit the link symbol, it assumes to be the same as the name of the SQL function being defined

 

SQL Body

Specifies the body of a LANGUAGE SQL function. This can either be a single statement

 

Returns Options

Function Type

Specifies the type of the function

Scalar: Specifies that it uses the default return type and emits all parameters.

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

Type: Specifies to accept user-defined function type

Return Data Type

Specifies the return data type of the function

 

Return Table Definition

Specify the referenced table

 

Return Table Column Specification

Specifies the schema of table columns that the function returns

 

Parameters

 

Parameters

Specifies the name of the parameter

 

 

Physical Data Type

Specifies the return data type of the parameter

 

 

Mode

Specifies the type of the parameter

 

 

Default Value

Specifies an expression that can 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.

 

Variables

 

Variables

Specifies the name of the variable

 

 

Variable value

Specifies an expression to use as the variable value

 

  1. Work with the other tabs in the editor to access additional design features, for example:
  2. (Optional) Click the Comment tab and enter any comments you want to associate with the object.
  3. (Optional) Click the Where Used tab to view where the object is used within the model.
  4. (Optional) Click the UDP tab to work with user-defined properties for the object.
  5. (Optional) Click the Notes tab to view and edit user notes.
  6. (Optional) Click the Extended Notes tab to view or edit user notes.
  7. Click Close.

    The function is defined and the PostgreSQL Function Editor closes.

For more information, refer to PostgreSQL documentation.