Skip to content

Commit 76fd9e7

Browse files
committed
Avoid using Gs for Gigaseconds, that's actually gauss.
1 parent 18c5c88 commit 76fd9e7

File tree

8 files changed

+52
-18
lines changed

8 files changed

+52
-18
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
7.0: Jul ?, 2018
22
----------------
33
* Format time using commonyears + days + hh:mm:ss.sss s.
4+
* Avoid using Gs for Gigaseconds, that's actually gauss.
45
* Modify @(unit, text) operator to return text instead of cstring.
56
* Import definitions.units from GNU units 2.17 with 13 new units.
67
* Add π to known units.

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
postgresql-unit (7.0-1) UNRELEASED; urgency=medium
22

33
* Format time using commonyears + days + hh:mm:ss.sss s.
4+
* Avoid using Gs for Gigaseconds, that's actually gauss.
45
* Modify @(unit, text) operator to return text instead of cstring.
56
* Import definitions.units from GNU units 2.17 with 13 new units.
67
* Add π to known units.

expected/crosstab.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ WHERE
8888
1e+18 | 1e+18 | 1 Em | 1 Zg | 1 Es | 1 EA | 1 EK | 1 Emol | 1 Ecd | 1 EB | 1 EHz | 1 EN | 1 EPa | 1 EJ | 1 EW | 1 EC | 1 EV | 1 EF | 1 EΩ | 1 ES | 1 EWb | 1 ET | 1 EH | 1 Elx | 1 EGy | 1 Ekat
8989
1e+15 | 1e+15 | 1 Pm | 1 Eg | 1 Ps | 1 PA | 1 PK | 1 Pmol | 1 Pcd | 1 PB | 1 PHz | 1 PN | 1 PPa | 1 PJ | 1 PW | 1 PC | 1 PV | 1 PF | 1 PΩ | 1 PS | 1 PWb | 1 PT | 1 PH | 1 Plx | 1 PGy | 1 Pkat
9090
1000000000000 | 1000000000000 | 1 Tm | 1 Pg | 1 Ts | 1 TA | 1 TK | 1 Tmol | 1 Tcd | 1 TB | 1 THz | 1 TN | 1 TPa | 1 TJ | 1 TW | 1 TC | 1 TV | 1 TF | 1 TΩ | 1 TS | 1 TWb | 1 TT | 1 TH | 1 Tlx | 1 TGy | 1 Tkat
91-
1000000000 | 1000000000 | 1 Gm | 1 Tg | 1 Gs | 1 GA | 1 GK | 1 Gmol | 1 Gcd | 1 GB | 1 GHz | 1 GN | 1 GPa | 1 GJ | 1 GW | 1 GC | 1 GV | 1 GF | 1 GΩ | 1 GS | 1 GWb | 1 GT | 1 GH | 1 Glx | 1 GGy | 1 Gkat
91+
1000000000 | 1000000000 | 1 Gm | 1 Tg | 1 Gsec | 1 GA | 1 GK | 1 Gmol | 1 Gcd | 1 GB | 1 GHz | 1 GN | 1 GPa | 1 GJ | 1 GW | 1 GC | 1 GV | 1 GF | 1 GΩ | 1 GS | 1 GWb | 1 GT | 1 GH | 1 Glx | 1 GGy | 1 Gkat
9292
1000000 | 1000000 | 1 Mm | 1 Gg | 1 Ms | 1 MA | 1 MK | 1 Mmol | 1 Mcd | 1 MB | 1 MHz | 1 MN | 1 MPa | 1 MJ | 1 MW | 1 MC | 1 MV | 1 MF | 1 MΩ | 1 MS | 1 MWb | 1 MT | 1 MH | 1 Mlx | 1 MGy | 1 Mkat
9393
1000 | 1000 | 1 km | 1 Mg | 1 ks | 1 kA | 1 kK | 1 kmol | 1 kcd | 1 kB | 1 kHz | 1 kN | 1 kPa | 1 kJ | 1 kW | 1 kC | 1 kV | 1 kF | 1 kΩ | 1 kS | 1 kWb | 1 kT | 1 kH | 1 klx | 1 kGy | 1 kkat
9494
1 | 1 | 1 m | 1 kg | 1 s | 1 A | 1 K | 1 mol | 1 cd | 1 B | 1 Hz | 1 N | 1 Pa | 1 J | 1 W | 1 C | 1 V | 1 F | 1 Ω | 1 S | 1 Wb | 1 T | 1 H | 1 lx | 1 Gy | 1 kat
@@ -286,9 +286,9 @@ WHERE
286286
l | 1e-27 m^3 | 1e-24 m^3 | 1e-21 m^3 | 1e-18 m^3 | 1e-15 m^3 | 1e-12 m^3 | 1e-09 m^3 | 1e-09 m^3 | 1e-06 m^3 | 1e-05 m^3 | 0.0001 m^3 | 0.001 m^3 | 0.01 m^3 | 0.1 m^3 | 1 m^3 | 1000 m^3 | 1000000 m^3 | 1000000000 m^3 | 1000000000000 m^3 | 1e+15 m^3 | 1e+18 m^3 | 1e+21 m^3
287287
t | 1 ag | 1 fg | 98.0665 kPa | 304.8 mm | 0.000473176473 m^3 | 1 N | 1 g | 1 g | 1 kg | 200 mg | 100 kg | 1 Mg | | 100 Mg | 1 Gg | 1 Tg | 1 Pg | 1 Eg | 1 Zg | 1 Yg | 1e+24 kg | 1e+27 kg
288288
bar | 100 zPa | 100 aPa | 100 fPa | 100 pPa | 100 nPa | 100 µPa | 100 mPa | 100 mPa | 100 Pa | 1 kPa | 10 kPa | 100 kPa | 1 MPa | 1.05457180005237e-34 m^2*kg/s | 100 MPa | 100 GPa | 100 TPa | 100 PPa | 100 EPa | 100 ZPa | 100 YPa | 1e+29 Pa
289-
min | 60 ys | 60 zs | 60 as | 60 fs | 60 ps | 60 ns | 60 µs | 60 µs | 60 ms | 600 ms | 6 s | 60 s | 600 s | 6 ks | 60 ks | 60 Ms | 60 Gs | 60 Ts | 60 Ps | 60 Es | 60 Zs | 60 Ys
290-
h | 3.6 zs | 3.6 as | 3.6 fs | 3.6 ps | 10 klx | 3.6 µs | 3.6 ms | 3.6 ms | 1 mH | 20.1168 m | 360 s | 3.6 ks | 36 ks | 360 ks | 3.6 Ms | 3.6 Gs | 3.6 Ts | 3.6 Ps | 3.6 Es | 3.6 Zs | 3.6 Ys | 3.6e+27 s
291-
d | 914.4 mm | 86.4 as | 86.4 fs | 86.4 ps | 86.4 ns | 86.4 µs | 86.4 ms | 86.4 ms | 86.4 s | 1 cd | 8.64 ks | 86.4 ks | 864 ks | 0.238480942392 m^3 | 86.4 Ms | 86.4 Gs | 86.4 Ts | 86.4 Ps | 86.4 Es | 86.4 Zs | 86.4 Ys | 8.64e+28 s
289+
min | 60 ys | 60 zs | 60 as | 60 fs | 60 ps | 60 ns | 60 µs | 60 µs | 60 ms | 600 ms | 6 s | 60 s | 600 s | 6 ks | 60 ks | 60 Ms | 60 Gsec | 60 Ts | 60 Ps | 60 Es | 60 Zs | 60 Ys
290+
h | 3.6 zs | 3.6 as | 3.6 fs | 3.6 ps | 10 klx | 3.6 µs | 3.6 ms | 3.6 ms | 1 mH | 20.1168 m | 360 s | 3.6 ks | 36 ks | 360 ks | 3.6 Ms | 3.6 Gsec | 3.6 Ts | 3.6 Ps | 3.6 Es | 3.6 Zs | 3.6 Ys | 3.6e+27 s
291+
d | 914.4 mm | 86.4 as | 86.4 fs | 86.4 ps | 86.4 ns | 86.4 µs | 86.4 ms | 86.4 ms | 86.4 s | 1 cd | 8.64 ks | 86.4 ks | 864 ks | 0.238480942392 m^3 | 86.4 Ms | 86.4 Gsec | 86.4 Ts | 86.4 Ps | 86.4 Es | 86.4 Zs | 86.4 Ys | 8.64e+28 s
292292
in | 2.54e-26 m | 25.4 ym | 25.4 zm | 25.4 am | 0.020457405 m^3 | 25.4 pm | 25.4 nm | 25.4 nm | 60 s | 254 µm | 2.54 mm | 25.4 mm | 254 mm | 2.54 m | 600 g | 25.4 km | 25.4 Mm | 25.4 Gm | 25.4 Tm | 25.4 Pm | 25.4 Em | 25.4 Zm
293293
ft | 3.048e-25 m | 304.8 ym | 304.8 zm | 304.8 am | 304.8 fm | 304.8 pm | 304.8 nm | 304.8 nm | 304.8 µm | 3.048 mm | 30.48 mm | 304.8 mm | 3.048 m | 30.48 m | 304.8 m | 304.8 km | 304.8 Mm | 304.8 Gm | 304.8 Tm | 304.8 Pm | 304.8 Em | 304.8 Zm
294294
yd | 9.144e-25 m | 914.4 ym | 914.4 zm | 914.4 am | 914.4 fm | 914.4 pm | 914.4 nm | 914.4 nm | 914.4 µm | 9.144 mm | 91.44 mm | 914.4 mm | 9.144 m | 91.44 m | 914.4 m | 914.4 km | 914.4 Mm | 914.4 Gm | 914.4 Tm | 914.4 Pm | 914.4 Em | 914.4 Zm

expected/time.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ SELECT name, unit, definition FROM unit_units WHERE dimension(unit) = 'TIME' ORD
265265
cron | 1.00066e+06 commonyear + 203 d + 18:44:38.4 s | 1e6 years
266266
(100 rows)
267267

268+
-- units that differ when pushed through output-input functions
269+
-- (same test as in units.sql, but with time_output_custom = true)
270+
SELECT name, unit, unit::text::unit, definition FROM unit_units WHERE unit::text::unit::text <> unit::text;
271+
name | unit | unit | definition
272+
------+------+------+------------
273+
(0 rows)
274+
268275
/* custom time format is only used if dimension is time */
269276
SELECT '1000 s'::unit, '1000 s/m'::unit;
270277
unit | unit
@@ -279,3 +286,10 @@ SELECT '1000 s'::unit, '1000 s/m'::unit;
279286
1 ks | 1 ks/m
280287
(1 row)
281288

289+
-- test if 'Gs' is avoided on output
290+
SELECT '1 Gsec'::unit, '1 Gsec/m'::unit;
291+
unit | unit
292+
--------+----------
293+
1 Gsec | 1 Gsec/m
294+
(1 row)
295+

expected/units.out

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,12 @@ SELECT name, unit, definition FROM unit_units ORDER BY dimension(unit), unit, na
675675
jupiteryear | 374.355659124 Ms | 11.862615 julianyear
676676
saros | 568.9717444 Ms | 223 synodicmonth
677677
saturnyear | 929.2923628848 Ms | 29.447498 julianyear
678-
uranusyear | 2.6513700193296 Gs | 84.016846 julianyear
679-
century | 3.15569259746784 Gs | 100 years
680-
neptuneyear | 5.200418560032 Gs | 164.79132 julianyear
681-
plutoyear | 7.82378070444 Gs | 247.92065 julianyear
682-
millennia | 31.5569259746784 Gs | millennium
683-
millennium | 31.5569259746784 Gs | 1000 years
678+
uranusyear | 2.6513700193296 Gsec | 84.016846 julianyear
679+
century | 3.15569259746784 Gsec | 100 years
680+
neptuneyear | 5.200418560032 Gsec | 164.79132 julianyear
681+
plutoyear | 7.82378070444 Gsec | 247.92065 julianyear
682+
millennia | 31.5569259746784 Gsec | millennium
683+
millennium | 31.5569259746784 Gsec | 1000 years
684684
cron | 31.5569259746784 Ts | 1e6 years
685685
LUMINOUS_ENERGY | 1 s*cd | talbot
686686
lumberg | 1 s*cd | talbot
@@ -2673,6 +2673,12 @@ SELECT name, unit, definition, definition::unit AS parsed_definition, unit / def
26732673
------+------+------------+-------------------+-----------
26742674
(0 rows)
26752675

2676+
-- units that differ when pushed through output-input functions
2677+
SELECT name, unit, unit::text::unit, definition FROM unit_units WHERE unit::text::unit::text <> unit::text;
2678+
name | unit | unit | definition
2679+
------+------+------+------------
2680+
(0 rows)
2681+
26762682
-- prefix-unit combinations that are ambiguous
26772683
/*
26782684
CREATE OR REPLACE FUNCTION valid_unit(u text)

sql/time.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ SELECT '1.1 d'::unit; -- needs ULP clamping
3030

3131
SELECT name, unit, definition FROM unit_units WHERE dimension(unit) = 'TIME' ORDER BY unit, name;
3232

33+
-- units that differ when pushed through output-input functions
34+
-- (same test as in units.sql, but with time_output_custom = true)
35+
SELECT name, unit, unit::text::unit, definition FROM unit_units WHERE unit::text::unit::text <> unit::text;
36+
3337
/* custom time format is only used if dimension is time */
3438
SELECT '1000 s'::unit, '1000 s/m'::unit;
3539
SET unit.time_output_custom = false;
3640
SELECT '1000 s'::unit, '1000 s/m'::unit;
41+
42+
-- test if 'Gs' is avoided on output
43+
SELECT '1 Gsec'::unit, '1 Gsec/m'::unit;

sql/units.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ SELECT name, unit, definition FROM unit_units ORDER BY dimension(unit), unit, na
88
SELECT name, unit, definition, definition::unit AS parsed_definition, unit / definition::unit AS deviation
99
FROM unit_units WHERE unit <> definition::unit;
1010

11+
-- units that differ when pushed through output-input functions
12+
SELECT name, unit, unit::text::unit, definition FROM unit_units WHERE unit::text::unit::text <> unit::text;
13+
1114
-- prefix-unit combinations that are ambiguous
1215
/*
1316
CREATE OR REPLACE FUNCTION valid_unit(u text)

unit.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ unit_cstring (Unit *unit)
410410
double v_abs = fabs(unit->value);
411411
char *prefix = "";
412412
double factor = 1.0;
413+
char *unit_name = derived_unit ? derived_unit->name : (char *)base_units[u_numerator];
413414

414415
/* case 2a: minute/hour/day output requested, unit is seconds, and
415416
* absolute value is >= 60 seconds. Print as interval and exit */
@@ -433,6 +434,8 @@ unit_cstring (Unit *unit)
433434
prefix = "T"; factor = 1e-12;
434435
} else if (v_abs >= POWER_9) {
435436
prefix = "G"; factor = 1e-9;
437+
if (!strcmp(unit_name, "s"))
438+
unit_name = "sec"; /* avoid Gs because it's gauss, not time */
436439
} else if (v_abs >= POWER_6) {
437440
prefix = "M"; factor = 1e-6;
438441
} else if (v_abs >= POWER_3) {
@@ -457,16 +460,15 @@ unit_cstring (Unit *unit)
457460
prefix = "y"; factor = 1e24;
458461
} /* else do nothing */
459462

460-
/* case 2b: derived unit, print with SI prefix and exit */
461-
if (derived_unit) {
462-
print_output("%s %s%s", float8out_internal (unit->value * factor),
463-
prefix, derived_unit->name);
463+
/* print with SI prefix */
464+
print_output("%s %s%s", float8out_internal (unit->value * factor),
465+
prefix, unit_name);
466+
467+
/* case 2b: derived unit: stop here */
468+
if (derived_unit)
464469
return output;
465-
}
466470

467-
/* case 2c: single unit in numerator (exponent 1), print with SI prefix and continue */
468-
print_output("%s %s%s", float8out_internal (unit->value * factor),
469-
prefix, base_units[u_numerator]);
471+
/* case 2c: single unit in numerator (exponent 1): continue */
470472
numerator = true;
471473

472474
/* case 3: zero or more than one unit in numerator */

0 commit comments

Comments
 (0)