Contents
CREATE FUNCTION
A DDL command for defining a function
CREATE FUNCTION
is a DDL command for defining a function.
CREATE FUNCTION
has always been present in PostgreSQL.
Change history
- PostgreSQL 14
- support for SQL-standard function bodies when creating SQL functions (commit e717a9a1)
- PostgreSQL 12
- option
SUPPORT
added (commit 1fb57af9)
- option
- PostgreSQL 11
- obsolete and non-standard
WITH
clause removed (commit 4971d2a3)
- obsolete and non-standard
- PostgreSQL 9.6
PARALLEL { UNSAFE | RESTRICTED | SAFE }
option added (commit 7aea8e4f)
- PostgreSQL 9.5
TRANSFORM
attribute added (commit cac76582)
- PostgreSQL 8.4
- PostgreSQL 8.3
- PostgreSQL 8.1
- support for
IN
/OUT
/INOUT
parameters (initial commit 47888fe8)
- support for
- PostgreSQL 7.3
- syntax revised to match SQL99 standard (commit 94bdc485)
Note: any changes prior to PostgreSQL 7.3 are not reflected in this list.
Examples
Basic execution of CREATE FUNCTION
:
postgres=# CREATE FUNCTION foo() RETURNS INT LANGUAGE SQL AS $$ SELECT 1; $$; CREATE FUNCTION postgres=# SELECT foo(); foo ----- 1 (1 row)
Replacing the function body:
postgres=# CREATE OR REPLACE FUNCTION foo() RETURNS INT LANGUAGE SQL AS $$ SELECT 2; $$; CREATE FUNCTION postgres=# SELECT foo(); foo ----- 2 (1 row)
References
- PostgreSQL documentation: CREATE FUNCTION