Documentation
 
 
 

9.3. General Conversion Rules

Any data type conversion whether done implicitly, or done explicitly by casting or conversion functions must obey the following rules.

When the target is an integer type (SMALLINT, INTEGER, BIGINT)

  • The target must be large enough so that there is no loss of digits to the left of the decimal point in the source value.

  • If the source value has decimal digits, the outcome depends upon the individual case described previously.

  • If the source is a character data type, it must contain a valid numeric literal.

When the target is a floating point type (REAL, DOUBLE PRECISION)

  • The value of the source is rounded to the number of digits of precision of the target type (6 digits for REAL, 15 for DOUBLE PRECISION).

  • If the source is a character data type, it must contain a valid numeric literal.

When the target is the NUMERIC data type

  • The target must be large enough so that there is no loss of digits to the left of the decimal point in the source value.

  • The value of the source is rounded to the scale of the target type.

  • If the source is a character data type, it must contain a valid numeric literal.

When the target is a character data type (CHAR, VARCHAR, TEXT)

  • The target must be large enough to hold all non-blank characters of the source value, left-justified in the target variable. This includes the formatted output of values from source numeric and timestamp data types.

When the target is a timestamp data type (DATE, TIMESTAMP)

  • If the source is not a timestamp data type (i.e., the source is a character data type or an integer data type in some limited circumstances), it must contain a valid date or timestamp literal.

 
 ©2004-2007 EnterpriseDB All Rights Reserved