Explicit casts on fields of a named row type
When you explicitly cast a value as a named row type,
the database server automatically invokes any implicit or explicit
casts that are used to convert field values to the target data type.
In the following statement, the explicit cast of col1 to type row_t automatically
invokes the explicit cast that converts a field value of type FLOAT
to d_float:
INSERT INTO tab3 SELECT col2::row_t FROM tab2
The
following INSERT statement includes an explicit cast to the row_t type.
The explicit cast to the row type also invokes an explicit cast to
convert the b field of type row_t from FLOAT to d_float.
In general, an explicit cast to a row type also invokes any explicit
casts on the individual fields (one-level deep) that the row type
contains to handle conversions.
INSERT INTO tab3 VALUES (ROW(5, 6.55::FLOAT)::row_t)
The
following statement is also valid and returns the same results as
the preceding statement. However, this statement shows all the explicit
casts that are performed to insert a row_t value into the tab3 table.
INSERT INTO tab3 VALUES (ROW(5, 6.55::float::d_float)::row_t)
In the preceding examples, the conversions between the b fields of the row types require two levels of casting. The database server handles any value that contains a decimal point as a DECIMAL type. In addition, no implicit casts exist between the DECIMAL and d_float data types, so two levels of casting are necessary: a cast from DECIMAL to FLOAT and a second cast from FLOAT to d_float.