The DROP FUNCTION
statement enables you to delete a user-defined function.
Prerequisites
To manage … | You must have … |
---|---|
Global inline functions |
Manage Global Functions role. |
Scoped inline functions |
Manage Scope Functions role, with permissions on the specified bucket and scope. |
Global external functions |
Manage Global External Functions role. |
Scoped external functions |
Manage Scope External Functions role, with permissions on the specified bucket and scope. |
For more details about user roles, see Authorization.
Syntax
drop-function ::= 'DROP' 'FUNCTION' function ( 'IF' 'EXISTS' )?
function |
Function Name
function ::= ( namespace ':' ( bucket '.' scope '.' )? )? identifier
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.
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 an external library, the external 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 JavaScript library and function.
To change or delete an external library or the external function code, you must use the Query Workbench or the SQL++ Functions REST API.
When you drop a SQL++ managed user-defined function, the associated external function code is deleted also.
Examples
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;
This statement deletes a SQL++ managed 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;
These statements delete two external functions:
-
A function called
geohash
, which depends on the JavaScriptencodeGeoHash
function in thegeohash-js
library; -
A function called
adjacent
, which depends on the JavaScriptcalculateAdjacent
function in thegeohash-js
library.
DROP FUNCTION geohash;
DROP FUNCTION adjacent;
You can run the following command to check that the JavaScript geohash-js
library and the encodeGeoHash
and calculateAdjacent
functions are still available.
curl -v -X GET \
http://localhost:8093/evaluator/v1/libraries/geohash-js \
-u Administrator:password
Related Links
-
To create user-defined functions, refer to CREATE FUNCTION.
-
To manage user-defined functions in the Query Workbench, see User-Defined Functions UI.
-
To manage external libraries and external functions, see Query Functions REST API.
-
To execute a user-defined function, see EXECUTE FUNCTION.
-
To see the execution plan for a user-defined function, see EXPLAIN FUNCTION.
-
To include a user-defined function in an expression, see User-Defined Functions.
-
To monitor user-defined functions, see Monitor Functions.