PL/TclU is the same, except
that the language has to be specified as pltclu.

The body of the function is simply a piece of Tcl script. When
the function is called, the argument values are passed as
variables $1 ... $n to the Tcl
script. The result is returned from the Tcl code in the usual
way, with a return statement.

For example, a function returning the greater of two integer
values could be defined as:

Note the clause STRICT, which saves
us from having to think about null input values: if a null value
is passed, the function will not be called at all, but will just
return a null result automatically.

In a nonstrict function, if the actual value of an argument is
null, the corresponding $n variable will be set to an empty
string. To detect whether a particular argument is null, use the
function argisnull. For example, suppose
that we wanted tcl_max with one
null and one nonnull argument to return the nonnull argument,
rather than null:

As shown above, to return a null value from a PL/Tcl function,
execute return_null. This can be done
whether the function is strict or not.

Composite-type arguments are passed to the function as Tcl
arrays. The element names of the array are the attribute names of
the composite type. If an attribute in the passed row has the
null value, it will not appear in the array. Here is an
example:

There is currently no support for returning a composite-type
result value, nor for returning sets.

PL/Tcl does not currently
have full support for domain types: it treats a domain the same
as the underlying scalar type. This means that constraints
associated with the domain will not be enforced. This is not an
issue for function arguments, but it is a hazard if you declare a
PL/Tcl function as returning a
domain type.

Add Comment

Please use this form to add your own comments regarding your experience with
particular features of PostgreSQL, clarifications of the documentation, or
hints for other users. Please note, this is not a support
forum, and your IP address will be logged. If you have a question or need help,
please see the faq, try a
mailing list, or join
us on IRC.
Note that submissions containing URLs or other keywords commonly found in
'spam' comments may be silently discarded. Please contact the
webmaster if you think this
is happening to you in error.