You can compare two unnamed row types that are structurally equivalent without an explicit cast. You can also compare an unnamed row type with another unnamed row type, if both row types have the same number of fields, and casts exist to convert values of corresponding fields that are not of the same data type. In other words, the cast from one unnamed row type to another is implicit if all the casts that handle field conversions are system-defined or implicit casts. Otherwise, you must explicitly cast an unnamed row type to compare it with another row type.
Suppose you create the following prices table:
CREATE TABLE prices (col1 ROW(a SMALLINT, b FLOAT) col2 ROW(x INT, y REAL) )
The values of the two unnamed row types can be compared (without an explicit cast) when built-in casts exist to perform conversions between corresponding fields. Consequently, the following query does not require an explicit cast to compare col1 and col2 values:
SELECT * FROM prices WHERE col1 = col2
In this example, the database server implicitly invokes a built-in cast to convert field values of SMALLINT to INT and REAL to FLOAT.
If corresponding fields of two row types cannot implicitly cast to one another, you can explicitly cast between the types, if a user-defined cast exists to handle conversions between the two types.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]