DROP FUNCTION

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Drops a temporary or permanent user-defined function (UDF).

Permissions

To drop a function in Unity Catalog, you must have the MANAGE privilege on the function or be its owner, and also USE CATALOG on the catalog and USE SCHEMA on the schema where the function resides.

Per the object hierarchy, owners of the parent schema or catalog and users with MANAGE on either can also perform this operation. The usage privileges they need depend on the object level at which they hold ownership or MANAGE. See Usage privilege requirements for MANAGE.

Syntax

DROP [ TEMPORARY ] FUNCTION [ IF EXISTS ] function_name

Parameters

  • function_name

    The name of an existing function. The function name may be optionally qualified with a schema name.

  • TEMPORARY

    Used to delete a TEMPORARY function.

  • IF EXISTS

    If specified, no exception is thrown when the function does not exist.

Examples

-- Create a permanent function `hello`
> CREATE FUNCTION hello() RETURNS STRING RETURN 'Hello World!';

-- Create a temporary function `hello`
> CREATE TEMPORARY FUNCTION hello() RETURNS STRING RETURN 'Good morning!';

-- List user functions
> SHOW USER FUNCTIONS;
  default.hello
          hello

-- Drop a permanent function
> DROP FUNCTION hello;

-- Try to drop a permanent function which is not present
> DROP FUNCTION hello;
Error: ROUTINE_NOT_FOUND

-- List the functions after dropping, it should list only temporary function
> SHOW USER FUNCTIONS;
 hello

-- Drop a temporary function if exists
> DROP TEMPORARY FUNCTION IF EXISTS hello;