Skip to content

Commit 372bd27

Browse files
committed
Rewire PostgreSQL 12's new extra_float_digits=1 default internally to 0 to keep nice, short decimal representations.
1 parent 342449e commit 372bd27

File tree

17 files changed

+130
-20
lines changed

17 files changed

+130
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ endif
2929
# upgrade testing, not enabled by default (needs extension actually installed)
3030
#REGRESS += upgrade
3131

32-
unit.o: unit.c unit.h defined_units.h float8out_internal.h
32+
unit.o: unit.c unit.h defined_units.h float8out_unit.h
3333

3434
unitparse.yy.c: unitparse.l
3535
flex -o $@ $<

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
7.2: unreleased
2+
----------------
3+
* Rewire PostgreSQL 12's new extra_float_digits=1 default internally to 0 to
4+
keep nice, short decimal representations.
5+
16
7.1: Dec 3, 2018
27
----------------
38
* Import definitions.unit 2.44 from units 2.18 with 36 new units.

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ SET
525525
82 ft
526526
```
527527

528+
*Note*: Starting with PostgreSQL 12, the default value for `extra_float_digits`
529+
is 1, so all printed float values are exact. This makes many converted units
530+
(like inch to meters) have a lengthy decimal representation ending in ...0001
531+
or ...9997. In order to restore the "nice" display behavior, e_f_t=1 is
532+
internally converted to e_f_t=0 in these PostgreSQL versions. Values returned
533+
as floats (like from the `value()` function and the `@@` operator) will still
534+
have the "new" representation; set e_f_t=0 to disable. Set e_f_t to 2 or 3 to
535+
force the new, exact representation.
536+
528537
References
529538
----------
530539

@@ -538,10 +547,10 @@ References
538547
License
539548
-------
540549

541-
Copyright (C) 2016-2018 Christoph Berg
550+
Copyright (C) 2016-2019 Christoph Berg
542551

543552
The definitions.units file is
544-
Copyright (C) 1996-2017 Free Software Foundation, Inc.
553+
Copyright (C) 1996-2018 Free Software Foundation, Inc.
545554

546555
This program is free software; you can redistribute it and/or modify
547556
it under the terms of the GNU General Public License as published by

debian/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
postgresql-unit (7.2-1) UNRELEASED; urgency=medium
2+
3+
* Rewire PostgreSQL 12's new extra_float_digits=1 default internally to 0 to
4+
keep nice, short decimal representations.
5+
6+
-- Christoph Berg <[email protected]> Thu, 16 May 2019 13:34:30 +0200
7+
18
postgresql-unit (7.1-1) unstable; urgency=medium
29

310
* Import definitions.unit 2.44 from units 2.18 with 36 new units.

expected/aggregate.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
-- test aggregates
2+
/* revert to pre-12 default for stddev(value()) tests */
3+
SET extra_float_digits = 0;
24
CREATE TEMP TABLE u (
35
u unit
46
);

expected/convert.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ FROM
2424
mi | 1609344 mm | 1609.344 m | 1.609344 km | 63360 in | 5280 ft | 1760 yd | 1 mi
2525
(7 rows)
2626

27+
/* revert to pre-12 default */
28+
SET extra_float_digits = 0;
2729
WITH
2830
l(u) AS (VALUES
2931
('mm'),
@@ -49,6 +51,7 @@ FROM
4951
mi | 1609344 | 1609.344 | 1.609344 | 63360 | 5280 | 1760 | 1
5052
(7 rows)
5153

54+
RESET extra_float_digits;
5255
-- area
5356
WITH
5457
l(u) AS (VALUES

expected/derived.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ SELECT katal(2);
263263
2 kat
264264
(1 row)
265265

266+
/* revert to pre-12 default for decibel() tests */
267+
SET extra_float_digits = 0;
266268
-- Non-SI units accepted for use with the SI
267269
SELECT minute();
268270
minute

expected/round_1.out

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
SELECT round(ampere(1.5));
2+
round
3+
-------
4+
2 A
5+
(1 row)
6+
7+
SELECT round(candela(-0.5));
8+
round
9+
-------
10+
-1 cd
11+
(1 row)
12+
13+
SELECT round(meter(1500.5));
14+
round
15+
----------
16+
1.501 km
17+
(1 row)
18+
19+
SET extra_float_digits = 0;
20+
SELECT '1|3m'::unit, '25m'::unit @ 'ft', '25m'::unit @@ 'ft';
21+
unit | ?column? | ?column?
22+
---------------------+---------------------+------------------
23+
333.333333333333 mm | 82.0209973753281 ft | 82.0209973753281
24+
(1 row)
25+
26+
SET extra_float_digits = 3;
27+
SELECT '1|3m'::unit, '25m'::unit @ 'ft', '25m'::unit @@ 'ft';
28+
unit | ?column? | ?column?
29+
------------------------+------------------------+-------------------
30+
333.333333333333314 mm | 82.0209973753280792 ft | 82.02099737532808
31+
(1 row)
32+
33+
SET extra_float_digits = -3;
34+
SELECT '1|3m'::unit, '25m'::unit @ 'ft', '25m'::unit @@ 'ft';
35+
unit | ?column? | ?column?
36+
------------------+------------------+---------------
37+
333.333333333 mm | 82.0209973753 ft | 82.0209973753
38+
(1 row)
39+
40+
SET extra_float_digits = -12;
41+
SELECT '1|3m'::unit, '25m'::unit @ 'ft', '25m'::unit @@ 'ft';
42+
unit | ?column? | ?column?
43+
--------+----------+----------
44+
333 mm | 82 ft | 82
45+
(1 row)
46+
47+
SET extra_float_digits = -15;
48+
SELECT '1|3m'::unit, '25m'::unit @ 'ft', '25m'::unit @@ 'ft';
49+
unit | ?column? | ?column?
50+
----------+----------+----------
51+
3e+02 mm | 8e+01 ft | 8e+01
52+
(1 row)
53+

expected/temperature.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* revert to pre-12 default */
2+
SET extra_float_digits = 0;
13
SELECT * FROM unit_units WHERE name IN (
24
'K', 'kelvin',
35
'℃', '°C', 'degC', 'degcelsius',
@@ -27,6 +29,7 @@ ORDER BY name COLLATE "C";
2729
℉ | 555.555555555556 mK | 255.372222222222 | degF |
2830
(18 rows)
2931

32+
RESET extra_float_digits;
3033
-- Kelvin
3134
SELECT '0 K'::unit, 'K'::unit, '1 K'::unit, '273.15 K'::unit;
3235
unit | unit | unit | unit

expected/units.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
SET unit.time_output_custom = false;
2+
/* revert to pre-12 default */
3+
SET extra_float_digits = 0;
24
SELECT prefix, factor, definition FROM unit_prefixes ORDER BY factor, prefix COLLATE "C";
35
prefix | factor | definition
46
----------+----------------------+------------
@@ -118,6 +120,7 @@ SELECT prefix, factor, definition FROM unit_prefixes ORDER BY factor, prefix COL
118120
yobi | 1.20892581961463e+24 | 2^80
119121
(114 rows)
120122

123+
RESET extra_float_digits;
121124
SELECT name, unit, definition FROM unit_units ORDER BY dimension(unit), unit, name COLLATE "C";
122125
name | unit | definition
123126
---------------------------+-------------------------------------+-----------------------------------------------

0 commit comments

Comments
 (0)