How CREATE FUNCTION and REPLACE FUNCTION Differ | VantageCloud Lake - Differences between CREATE FUNCTION and REPLACE FUNCTION for a UDT - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

A function can be created or replaced using the same syntax except for the keywords CREATE and REPLACE.

If you specify CREATE, the function must not exist.

If you specify REPLACE, you can either create a new function or replace an existing function with the following restriction: if the function to be replaced was originally created with a specific function name, then that specific function name must be used for the REPLACE FUNCTION statement.

When you replace an existing function, the replaced function does not retain the EXECUTE NOT PROTECTED attribute if one had previously been set using the ALTER FUNCTION statement. See When to Specify Unprotected Mode (ALTER FUNCTION External Form).

The advantage to using REPLACE is that you can avoid having to grant the EXECUTE privilege again to all users who already had that privilege on the function.

See the following topics for important restrictions on replacing UDFs that perform UDT-related functionality.

Replacing an Ordering or Transform UDF

A UDF that is being used to implement either the ordering or transform functionality for a UDT can only be replaced if the following conditions are met:
  • The REPLACE FUNCTION specification must match exactly with the existing method specification in the dictionary.

    The function name, parameter list, method entry point name within the EXTERNAL clause, and so on must all match.

  • The execution mode for the UDF being replaced must be set to EXECUTE PROTECTED.

    If the UDF is set to run in the EXECUTE NOT PROTECTED mode, then you must submit an ALTER FUNCTION statement to switch the mode to EXECUTE PROTECTED before you can submit the REPLACE FUNCTION statement. See When to Specify Unprotected Mode (ALTER FUNCTION External Form).

Replacing a Casting UDF for a UDT

A UDF that is being used to implement casting functionality for a UDT can only be replaced using the following procedure:
  1. DROP CAST
  2. REPLACE FUNCTION
  3. CREATE CAST

Trying to replace a casting function using REPLACE FUNCTION is an error.