To use a function in a SQL statement, type the function's name, followed by its list of parameters
(called
arguments
), if any. The arguments passed to a function are enclosed in parentheses. There
are two general styles of entering arguments: the standard SQL92 functions are generally implemented
so that they accept their arguments delimited by special SQL keywords, such as
FROM, FOR, and USING.
PostgreSQL-style functions, on the other hand, accept arguments delimited by commas (which you might expect if you
have experience with a programming language such as C).
Arguments may be constants, valid identifiers, or expressions. The particular arguments you need to pass to a function
will depend completely on the function being used, and its requirements: especially with regards to data types. With a
couple of exceptions, all functions require the open and closing parentheses following the function name, even if no
arguments are passed.
sql92_style_function
( {
argument
|
KEYWORD
} [...] )
pgsql_style_function
(
argument
[, ...] )
Note: The exceptions to the parenthetical function syntax are the SQL92 functions current_date,
current_time, and current_timestamp. These lack parentheses
to remain compatible with the SQL92 specification.
A powerful use of functions is that they may be nested, provided that the data type returned by a nested function is
compatible with the argument accepted by the function it is nested within. Functions may be nested to any depth:
function_name
(
nested_function_name
(
arguments
[, ...] ) [, ...] )
PostgreSQL defines a rich set of functions for its built-in data types. To view a complete list of functions available,
execute the \df slash command within
psql
. PostgreSQL
also supports extensibility of its function set through the CREATE FUNCTION command. See
Chapter 7 for more on this topic.
Note: The default name for a column that is described by a function in the target list will be the name
of the function, without trailing parentheses, or arguments (e.g., to_char).