In the object hierarchy of every database are Casts. You can add casts by selecting CREATE CAST from the Casts context menu. Once a cast has been created, it can be dropped. This section describes how to create and drop a cast with Administrator.
Unlike the other CREATE dialogs, the CREATE CAST dialog has no entry for cast name. This is because casts do not have names; they are called automatically via the CAST AS/source::target/etc. syntax.
The first field is the Source Type. This specifies the type FROM which the cast will do the conversion. Casts cannot be created with types that exist in schemas that are not in the default path. Therefore the source type combo-box contains names of types that exist in the search path only.
The next field is the Target Type. This specifies the type TO which the cast will do the conversion. Like source type, types provided in this combo-box are the ones that exist in the search path only.
Below that are radio buttons for WITH/WITHOUT FUNCTION. If WITHOUT FUNCTION is selected, the cast is created without any associated function for the conversion. Conversely, WITH FUNCTION enables you to select the function to be used for casting.
![]() | Note |
|---|---|
To create a cast without a function, the source type and target type should be compatible. |
Last is the context. Refer to the PostgreSQL 7.3 Reference Manual for more information on how the context options work.
For this example, you will create a cast from int42 to int4. The data type int42 exists in the regression database that is created when the PostgreSQL - Red Hat Edition regression tests are run. Alternatively, you can manually create this type yourself; the definitions exist in: /usr/lib/pgsql/test/regress/sql/create_type.sql
To create a cast, expand the database under which the cast is to be created (click the [O-] beside the database name).
Right-click on the casts header and select CREATE CAST. A dialog box for CREATE CAST appears.
The first field is source type. Select int42 as the source type.
The next field is the target type. Select int4 as the target type.
Next are radio buttons that specify whether or not you want to use a function for the conversion. For this example, there is no need for a function, so keep the WITHOUT FUNCTION checked.
Last is the context. These radio boxes enable you to select the context in which this cast can be invoked. Leave this set to Explicit.
Click OK to create the cast.
Note that the cast has been added under the Casts node in the Tree View.
Administrator also enables you to perform the following operation on existing casts:
To drop a cast, right-click on the cast and select either DROP RESTRICT or DROP CASCADE. DROP RESTRICT will not drop the cast if there are any dependent objects. DROP CASCADE automatically drops the cast and all objects that depend on it.
If Preferences => Ask For Confirmations is enabled, you are asked to confirm that you want the cast dropped (and all the dependent objects in case of a DROP CASCADE); if it is disabled, the cast is dropped immediately (along with its dependent objects if DROP CASCADE was selected). This action cannot be undone.