DROP FUNCTION

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

Drops a temporary or permanent user-defined function (UDF). To drop a function you must be its owner, or the owner of the schema, catalog, or metastore the function resides in.

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;
Function 'default.hello' not found in schema 'default'

-- 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;