Re: Unit conversion database (was: multiple paramters in aggregate function)

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>, Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Unit conversion database (was: multiple paramters in aggregate function)
Date: 2009-08-19 19:40:58
Message-ID: 407d949e0908191240p57abb22el3ca2b5d35e792d25@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Aug 19, 2009 at 8:24 PM, Alvaro
Herrera<alvherre(at)commandprompt(dot)com> wrote:
>> [1] It doesn't correctly convert °C to °F or vv, that was one of the
>> first things I tried.
>
> Seems it's easy to misuse it.  You need tempF(x) and tempC notation for
> converting absolute temperature differences:
>
> You have: tempF(212)
> You want: tempC
>        100

That depends on whether you're converting a temperature or a
temperature difference. If you want to know what a 100 degree C drop
in temperature equates to in Fahrenheit the answer is not 212 but
rather 180.

I think it would be useful to have a builtin data type which contained
a float and an opaque text unit. It could support linear operations
like +, -, and sum() by just throwing an error if the units didn't
match.

Then you could add an add-on function which converted one such datum
to another with a desired new units by calling out to the units
program.

That would allow people to store values with heterogenous units. So
for example you could have SMART stats in a single table where the
time values, unitless values, and temperature values are all in the
same column. As long as you only compare, say, drive temperatures to
max temperatures you never actually need to know about the units. It
would serve as an assertion check to ensure you don't compare drive
temperatures to error counts or something like that.

--
greg
http://mit.edu/~gsstark/resume.pdf

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-08-19 19:49:32 Re: Re: Unit conversion database (was: multiple paramters in aggregate function)
Previous Message Alvaro Herrera 2009-08-19 19:24:28 Re: Unit conversion database (was: multiple paramters in aggregate function)