1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add casts from int4 and int8 to numeric.

Joey Adams, per gripe from Ramanujam.  Review by myself and Tom Lane.
This commit is contained in:
Robert Haas
2011-04-05 09:35:43 -04:00
parent 88f32b7ca2
commit f5e524d92b
8 changed files with 161 additions and 7 deletions

View File

@ -886,15 +886,22 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
</para>
<para>
Values of the <type>numeric</type> data type can be cast to
<type>money</type>. Other numeric types can be converted to
<type>money</type> by casting to <type>numeric</type> first, for example:
Values of the <type>numeric</type>, <type>int</type>, and
<type>bigint</type> data types can be cast to <type>money</type>.
Conversion from the <type>real</type> and <type>double precision</type>
data types can be done by casting to <type>numeric</type> first, for
example:
<programlisting>
SELECT 1234::numeric::money;
SELECT '12.34'::float8::numeric::money;
</programlisting>
However, this is not recommended. Floating point numbers should not be
used to handle money due to the potential for rounding errors.
</para>
<para>
A <type>money</type> value can be cast to <type>numeric</type> without
loss of precision. Conversion to other types could potentially lose
precision, and it must be done in two stages, for example:
precision, and must also be done in two stages:
<programlisting>
SELECT '52093.89'::money::numeric::float8;
</programlisting>