9.1. Converting Data Types

Numeric data types are all mutually comparable and mutually assignable. If an assignment will result in a loss of the most significant digits, an exception condition is raised. If the least significant digits are lost, the implementation defines what rounding or truncating has occurred and does not report an exception condition. Most often, one value is converted to the same data type as the other, and then the comparison is done in the usual way. The chosen data type is the “higher” of the two, using the following ordering: SMALLINT, INTEGER, BIGINT, DECIMAL, NUMERIC, REAL, FLOAT, DOUBLEPRECISION.

Floating-point hardware will often affect comparisons for REAL, FLOAT, and DOUBLEPRECISION numbers. There is no good way ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.