Skip to content

Commit b38c523

Browse files
committed
round(unit) rounds unit to nearest integer
Part of #11.
1 parent 9d6c787 commit b38c523

File tree

9 files changed

+651
-8
lines changed

9 files changed

+651
-8
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ DATA = unit_prefixes.data unit_units.data \
55
unit--1.sql unit--1--2.sql \
66
unit--2.sql
77
DATA_built = unit--2--3.sql unit--3.sql \
8-
unit--3--4.sql unit--4.sql
8+
unit--3--4.sql unit--4.sql \
9+
unit--4--5.sql unit--5.sql
910
REGRESS = extension tables unit unicode prefix units temperature functions derived compare aggregate iec custom
1011
EXTRA_CLEAN = unitparse.yy.* powers powers.o unit-*.dump # unitparse.tab.*
1112

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function cbrt(unit)
266266
function dimension(unit)
267267
function max(unit)
268268
function min(unit)
269+
function round(unit)
269270
function sqrt(unit)
270271
function stddev_pop(unit)
271272
function stddev_samp(unit)
@@ -318,6 +319,10 @@ Details:
318319

319320
Returns the numeric part of a unit value.
320321

322+
* **function round(unit): unit**
323+
324+
Rounds a unit value to the nearest integer (in base units).
325+
321326
References
322327
----------
323328

debian/changelog

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
postgresql-unit (4.0-3) UNRELEASED; urgency=medium
1+
postgresql-unit (5.0-1) UNRELEASED; urgency=medium
22

3+
* Add rounding functions.
34
* Import definitions.units from GNU units 2.16 with 70 new units.
45
(The file header erroneously says 2.19.)
56
* debian/watch: Ignore debian/ tags.
67

7-
-- Christoph Berg <[email protected]> Tue, 28 Nov 2017 20:23:01 +0100
8+
-- Christoph Berg <[email protected]> Tue, 02 Jan 2018 18:53:55 +0100
89

910
postgresql-unit (4.0-2) unstable; urgency=medium
1011

expected/functions.out

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- text extractors
1+
-- text functions
22
SELECT value('2'::unit);
33
value
44
-------
@@ -23,6 +23,18 @@ SELECT dimension(kilogram(2));
2323
1 kg
2424
(1 row)
2525

26+
SELECT round(ampere(1.5));
27+
round
28+
-------
29+
2 A
30+
(1 row)
31+
32+
SELECT round(candela(-0.5));
33+
round
34+
-------
35+
-1 cd
36+
(1 row)
37+
2638
-- test unit addition/subtraction
2739
SELECT '1'::unit + '2' AS sum;
2840
sum

sql/functions.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
-- text extractors
1+
-- test functions
22
SELECT value('2'::unit);
33
SELECT value(meter(2));
44
SELECT dimension('2'::unit);
55
SELECT dimension(kilogram(2));
6+
SELECT round(ampere(1.5));
7+
SELECT round(candela(-0.5));
68

79
-- test unit addition/subtraction
810
SELECT '1'::unit + '2' AS sum;

unit--4--5.sql.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE FUNCTION round(unit)
2+
RETURNS unit
3+
AS '$libdir/unit', 'unit_round'
4+
LANGUAGE C IMMUTABLE STRICT;

0 commit comments

Comments
 (0)