DROP FUNCTION

  • Capella Operational
  • reference
    +
    The DROP FUNCTION statement enables you to delete a user-defined function.

    Prerequisites

    Syntax

    drop-function ::= 'DROP' 'FUNCTION' function ( 'IF' 'EXISTS' )?
    Syntax diagram: refer to source code listing
    function

    Function Name

    Function Name

    function ::= ( namespace ':' ( bucket '.' scope '.' )? )? identifier
    Syntax diagram: refer to source code listing

    The name of the function. This is usually an unqualified identifier, such as func1 or `func-1`. In this case, the path to the function is determined by the current query context.

    To delete a global function in a particular namespace, the function name must be a qualified identifier with a namespace, such as default:func1. Similarly, to delete a scoped function in a particular scope, the function name must be a qualified identifier with the full path to a scope, such as default:`travel-sample`.inventory.func1. Refer to Global Functions and Scoped Functions for more information.

    You cannot have 2 functions with the same name in the same scope. You can have 2 functions in the same name across different scopes.

    The name of a user-defined function is case-sensitive, unlike that of a built-in function. You must delete the user-defined function using the same case that was used when it was created.

    IF EXISTS Clause

    The optional IF EXISTS clause enables the statement to complete successfully when the specified function doesn’t exist.

    When the function does not exist within the specified context: [1]

    • If this clause is not present, an error is generated.

    • If this clause is present, the statement does nothing and completes without error.

    Usage

    When you drop a user-defined function whose definition is stored in a UDF library, the library and function on which the user-defined function depended are not deleted. This enables you to create a new user-defined function with a different name, or a different number of parameters, using the same UDF library and JavaScript function.

    To change or delete a UDF library or the JavaScript function code, see Delete a User-Defined Function Library.

    When you drop an inline SQL++ user-defined function, the associated JavaScript function code is deleted also.

    Examples

    Example 1. Drop an inline function

    This statement deletes an inline function called celsius.

    DROP FUNCTION celsius;

    You can run the following query to check that the function is no longer available.

    SELECT * FROM system:functions;
    Example 2. Drop a SQL++ managed user-defined function

    This statement deletes an inline SQL++ user-defined function called add100.

    DROP FUNCTION add100 IF EXISTS;

    You can run the following query to check that the function is no longer available.

    SELECT * FROM system:functions;
    Example 3. Drop a UDF library function

    These statements delete two UDF library functions:

    1. A function called geohash, which depends on the JavaScript encodeGeoHash function in the geohash-js library;

    2. A function called adjacent, which depends on the JavaScript calculateAdjacent function in the geohash-js library.

    DROP FUNCTION geohash;
    
    DROP FUNCTION adjacent;

    1. That is, you are dropping a global function, and the function does not exist within the specified namespace; or, you are dropping a scoped function, and the function does not exist within the specified scope.