Create cast functions for user-defined casts
If your database contains opaque data types, distinct
data types, or named row types, you might want to create user-defined
casts that allow you to convert between the different data types.
When you want to perform conversions between two data types that have
the same storage structure, you can use the CREATE CAST statement
without a cast function. However, in some cases you must create a
cast function that you then register as a cast. You must create a
cast function under the following conditions:
- The conversion is between two data types that have different storage structures
- The conversion involves the manipulation of values to ensure that data conversions are meaningful
The following sections show how to create and use user-defined casts that require cast functions.