DROP FUNCTION

S’applique à :case marquée oui Databricks SQL case marquée oui Databricks Runtime

Supprime une fonction définie par l’utilisateur (UDF) temporaire ou permanente.

Permissions

Pour supprimer une fonction dans le catalogue Unity, vous devez avoir le MANAGE privilège sur la fonction ou en être le propriétaire, ainsi USE CATALOG que sur le catalogue et USE SCHEMA sur le schéma où la fonction réside.

Selon la hiérarchie d’objets, les propriétaires du schéma parent ou du catalogue et des utilisateurs sur utilisant MANAGE cette opération peuvent également effectuer cette opération. Les privilèges d’utilisation dont ils ont besoin dépendent du niveau de l’objet auquel ils détiennent la propriété ou MANAGE. Voir Exigences de privilèges d’utilisation pour MANAGE.

Syntaxe

DROP [ TEMPORARY ] FUNCTION [ IF EXISTS ] function_name

Paramètres

  • function_name

    Nom d’une fonction existante. Le nom de la fonction peut facultativement être qualifié avec un nom de schéma.

  • TEMPORARY

    Utilisé pour supprimer une fonction TEMPORARY.

  • S’IL EXISTE

    S’il est spécifié, aucune exception n’est levée lorsque la fonction n’existe pas.

Exemples

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