PostgreSQL Reference Manual - Volume 1 - SQL Language Referenceby The PostgreSQL Global Development Group Paperback (6"x9"), 716 pages ISBN 0954612027 RRP £32.00 ($49.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |

#### 2.1.2.4 Numeric Constants

Numeric constants are accepted in these general forms:

digitsdigits.[digits][e[+-]digits] [digits].digits[e[+-]digits]digitse[+-]digits

where `digits` is one or more decimal
digits (0 through 9). At least one digit must be before or after the
decimal point, if one is used. At least one digit must follow the
exponent marker (`e`

), if one is present.
There may not be any spaces or other characters embedded in the
constant. Note that any leading plus or minus sign is not actually
considered part of the constant; it is an operator applied to the
constant.

These are some examples of valid numeric constants:

42 3.5 4. .001 5e2 1.925e-3

A numeric constant that contains neither a decimal point nor an
exponent is initially presumed to be type `integer`

if its
value fits in type `integer`

(32 bits); otherwise it is
presumed to be type `bigint`

if its
value fits in type `bigint`

(64 bits); otherwise it is
taken to be type `numeric`

. Constants that contain decimal
points and/or exponents are always initially presumed to be type
`numeric`

.

The initially assigned data type of a numeric constant is just a
starting point for the type resolution algorithms. In most cases
the constant will be automatically coerced to the most
appropriate type depending on context. When necessary, you can
force a numeric value to be interpreted as a specific data type
by casting it.
For example, you can force a numeric value to be treated as type
`real`

(`float4`

) by writing

REAL '1.23' -- string style 1.23::REAL -- PostgreSQL (historical) style

These are actually just special cases of the general casting notations discussed next.

ISBN 0954612027 | PostgreSQL Reference Manual - Volume 1 - SQL Language Reference | See the print edition |