Updated on 2025-10-23 GMT+08:00

DROP FUNCTION

Description

Deletes a function.

This function is for internal use only and not available to users.

Precautions

  • If a function involves operations on temporary tables, DROP FUNCTION cannot be used.
  • Only the function owner or a user granted with the DROP permission can run the DROP FUNCTION command. The system administrator has this permission by default.

Syntax

DROP FUNCTION [ IF EXISTS ] function_name 
[ ( [ {[ argname ] [ argmode ] argtype} [, ...] ] ) [ CASCADE | RESTRICT ] ];

Parameters

  • IF EXISTS

    Specifies that a notice instead of an error is reported if the specified function does not exist.

  • function_name

    Specifies the name of the function to be deleted.

    Value range: an existing function name

  • argmode

    Specifies the parameter mode of the function.

  • argname

    Specifies the parameter name of the function.

  • argtype

    Specifies the parameter type of the function.

  • CASCADE | RESTRICT
    • CASCADE: automatically deletes the objects that depend on the function.
    • RESTRICT: refuses to delete the function if any objects depend on it. This is the default action.

Examples

  • Delete the list of parameters that can be omitted when a function.
    -- Create a function.
    m_db=# CREATE OR REPLACE FUNCTION func_add_sql(integer, integer) RETURNS bigint
    AS 'select $1 + $2;'
    LANGUAGE SQL
    IMMUTABLE
    SHIPPABLE
    STRICT
    AUTHID DEFINER
    not fenced
    COST 10000;
    /
    
    -- Delete the function.
    m_db=# DROP FUNCTION func_add_sql;
  • Delete a function with the same name.
    If a function with the same name exists, add a parameter list when deleting the function. Otherwise, an error is reported.
    -- Create a function.
    m_db=# CREATE OR REPLACE FUNCTION func_increment_plsql(i integer) RETURNS integer AS $$
    BEGIN
        RETURN i + 1;
    END;
    $$ LANGUAGE plpgsql;
    
    
    -- func_add is an overloaded function.
    m_db=# CREATE OR REPLACE FUNCTION func_add(int) RETURNS int AS $$
    BEGIN
        RETURN $1+10;
    END;
    $$ LANGUAGE PLPGSQL;
    
    -- Delete the function.
    m_db=# DROP FUNCTION func_add(int);
    m_db=# DROP FUNCTION func_add(int,int);

Helpful Links

CREATE FUNCTION