Using functions for various purposes
In PostgreSQL, stored procedures can be used for pretty much everything. In this chapter, you have already learned about the CREATE DOMAIN
clause and so on, but it is also possible to create your own operators, type casts, and even collations.
In this section, you will see how a simple type cast can be created and how it can be used to your advantage. To define a type cast, consider taking a look at the CREATE CAST
clause. The syntax of this command is shown in the following code:
test=# \h CREATE CAST Command: CREATE CAST Description: define a new cast Syntax: CREATE CAST (source_type AS target_type) WITH FUNCTION function_name [ (argument_type [, ...]) ] [ AS ASSIGNMENT | AS IMPLICIT ] CREATE CAST (source_type AS target_type) WITHOUT FUNCTION [ AS ASSIGNMENT | AS IMPLICIT ] CREATE CAST (source_type AS target_type) WITH INOUT ...