postgresql-unit
postgresql-unit copied to clipboard
Add option to retrieve the unit as text
Hello. I'm using this extension on a daily basis, but I've not found documentation or examples on this use case
When retrieving a unit from the database, I want the text part of unit in another column. I could use space separation, but that seems inefficient and prone to error.
Any suggestions are appreciated
Desired result, function used as a placeholder
SELECT
tonne(value) as value,
get_unit_text(tonne(value)) as unit
FROM value_double
LIMIT 10;
value | unit
-----------------------+----------
13.599363666572335 Mg | Mg
6.812643569443901 Mg | Mg
0 kg | kg
3.651819394991275 Tg | Tg
15.79587709758574 Tg | Tg
822.3106735537558 kg | kg
41.65109425967615 Mg | Mg
5.6431896649999995 Pg | Pg
822.3106735537558 kg | kg
5.6431896649999995 Pg | Pg