As stated in this chapter, functions in PostgreSQL are pretty universal and can be used in many different contexts. If you want to use functions to improve data quality, you can use a CREATE DOMAIN clause:
test=# \h CREATE DOMAIN Command: CREATE DOMAINDescription: Define a new domainSyntax:CREATE DOMAIN name [ AS ] data_type [ COLLATE collation ] [ DEFAULT expression ] [ constraint [ ... ] ] Here, constraint is as follows: [ CONSTRAINT constraint_name ] { NOT NULL | NULL | CHECK (expression) }
In this example, the PL/Perl function will be used to create a domain called email, which in turn can be used as a datatype.
The following listing shows how the domain can be created:
test=# CREATE DOMAIN email ...