Implicit Type Conversions

From InterBase
Jump to: navigation, search

Go Up to Converting Data Types


InterBase supports several types of implicit type conversion. For example, comparing a DATE or TIMESTAMP column to ‘6/7/2000’ causes the string literal ‘6/7/2000’ to be converted implicitly to a DATE entity. An expression mixing integers with scaled numeric types or float types implicitly converts the integer to a like type.

However, InterBase dialect 3 differs from dialect 1 in this respect: in dialect 3, implicit string-to-integer conversion is not supported. For example, in the following operation:

3 + '1' = 4
  • InterBase dialect 1 automatically converts the character “1” to an INTEGER for the addition.
  • InterBase dialect 3 returns an error.

In dialect 3, an explicit type conversion is needed:

3 + CAST(‘1’ AS INT)

The next example returns an error in either dialect, because InterBase cannot convert the “a” to an INTEGER:

3 + 'a' = 4