@@ -11,14 +11,18 @@ features of PostgreSQL's builtin NUMERIC type, but with vastly increased
1111performance. Fixeddecimal is targeted to cases where performance and disk space
1212are a critical.
1313
14+ Just use FIXEDDECIMAL(n, 2) rather than NUMERIC(n, 2) for n=3..17
15+
1416Often there are data storage requirements where the built in REAL and
1517DOUBLE PRECISION types cannot be used due to the non-exact representation of
1618numbers using these types, e.g. where monetary values need to be stored. In many
1719of these cases NUMERIC is an almost perfect type, although with NUMERIC
1820performance is no match for the performance of REAL or DOUBLE PRECISION, as
19- these use CPU native processor types. FixedDecimal aims to offer performance
20- advantages over NUMERIC without the imprecise representations that are
21- apparent in REAL and DOUBLE PRECISION, but it comes with some caveats...
21+ these use CPU native processor types.
22+
23+ FixedDecimal delivers performance advantages over NUMERIC with full precision for
24+ addition and subtraction. Just as occurs with REAL and DOUBLE PRECISION, there
25+ are some caveats for multiplication and division.
2226
2327Behavioural differences between FIXEDDECIMAL and NUMERIC
2428--------------------------------------------------------
@@ -50,8 +54,9 @@ implementations as in the case with NUMERIC.
5054FIXEDDECIMAL has a fixed scale value, which by default is 2. Internally numbers
5155are stores as the actual value multiplied by 100. e.g. 50 would be stored as
52565000, and 1.23 would be stored as 123. This internal representation allows very
53- fast addition and subtraction between two fixeddecimal types. Multiplication
54- between two fixeddecimal types is slightly more complex. If we wanted to
57+ fast and accurate addition and subtraction between two fixeddecimal types.
58+
59+ Multiplication between two fixeddecimal types is slightly more complex. If we
5560perform 2.00 * 3.00 in fixeddecimal, internally these numbers would be 200 and
5661300 respectively, so internally 200 * 300 becomes 60000, which must be divided
5762by 100 in order to obtain the correct internal result of 600, which of course
@@ -113,7 +118,7 @@ test=# select '1.239'::fixeddecimal;
113118
114119It is especially important to remember that this truncation also occurs during
115120arithmetic. Notice in the following example the result is 1120 rather than
116- 1129:
121+ 1129, since 1.129 is immediately rounded to 1.12 on input.
117122
118123```
119124test=# select '1000'::fixeddecimal * '1.129'::fixeddecimal;
0 commit comments