Routine resolution with built-in data types as source
If the source type is a built-in data type, the distinct
type does not inherit any built-in casts provided for the built-in
type, but it does inherit any user-defined casts that are defined
on the source type. For example, suppose you create the following
distinct data type and table:
CREATE DISTINCT TYPE inches AS FLOAT;
CREATE TABLE test(col1 inches);
INSERT INTO test VALUES (2.5::FLOAT::inches);
An
SQL user might execute the following sample query:
SELECT 4.8 + col1 FROM test;
Although
the source data type of the col1 argument has a built-in cast
function to convert from FLOAT to DECIMAL (the 4.8
is
DECIMAL), this query fails because the distinct type inches does
not inherit the built-in cast.
You must use explicit casts in
the SQL query. The following queries succeed:
SELECT 4.8 + col1::INT from test;
SELECT 4.8::FLOAT::inches + col1 FROM test;