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

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)

Categories

DDL, Functions and procedures

See also

ALTER FUNCTION, DROP FUNCTION, CREATE PROCEDURE, check_function_bodies