Create Function
Defines a new function within the database.
Synopsis
CREATE FUNCTION name ( [ argtype [, ...] ] ) RETURNS returntype AS 'definition' LANGUAGE 'langname' [ WITH ( attribute [, ...] ) ] CREATE FUNCTION name ( [ argtype [, ...] ] ) RETURNS returntype AS 'obj_file' [, 'link_symbol' ] LANGUAGE 'langname' [ WITH ( attribute [, ...] ) ]
Parameters
nameThe name of the new function being created.
argtypeThe data type of the argument, or arguments, to be accepted by the new function. There are three general input types you may use: base types, complex types, or the special
opaquetype. Theopaquetype explicitly allows the function to accept arguments of invalid SQL types. Theopaquetype is generally used by internal functions, or functions written in internal language such as C, or PL/pgSQL, where the return type is not provided as a standard SQL data type.returntypeThe data type of the value or values returned by the new function. This may be set as a base type, complex type,
setoftype (a normal data type, prefixed bysetof), or theopaquetype.Using the
setofmodifier determines that the function will return multiple rows worth of data (by default, a function returns only one row). For example, a return type defined assetof integercreates a function that can return more than a single row of integer values.attributeAn optional function attribute. Valid attributes, as of PostgreSQL 7.1.x, are
isstrictandiscacheable.definitionThe definition of the function to create. This ...