WITH Clause

The WITH clause of the CREATE CAST statement specifies the name of the user-defined function to invoke to perform the cast. This function is called the cast function.

You must specify a function name unless the source data type and the target data type have identical representations. Two data types have identical representations when the following conditions are met:
  • Both data types have the same length and alignment.
  • Both data types are passed by reference or both are passed by value.

The cast function must be registered in the same database as the cast at the time the cast is invoked, but need not exist when the cast is created. The CREATE CAST statement does not check privileges on the specified function name, or even verify that the cast function exists. Each time a user invokes the cast explicitly or implicitly, the database server verifies that the user has the Execute privilege on the cast function.