Re: Extended unit - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Extended unit
Date
Msg-id 20050125102200.GF29308@svana.org
Whole thread Raw
In response to Extended unit  (Pailloncy Jean-Gerard <jg@rilk.com>)
Responses Re: Extended unit  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
On Tue, Jan 25, 2005 at 10:40:15AM +0100, Pailloncy Jean-Gerard wrote:
> Hi,
>
> My question is purely theoretical.
>
> I add use in my time in University some software that use "extended
> type".
> For each variable, we define the mandatory "classic type" as integer,
> float, double array of.
> And we define an optional "extended type" as the unit in the MKSA
> system (Meter, Kilogram, Second, Ampere) or any other unit we would
> have previously define (eg. Currency).
>
> This "extended type" was wonderful, because there was warning/error if
> "extend type" does not match in any computation: you can not add apple
> to orange.

I think it's a wonderful idea. You could use a similar mechanism to
implement:

- Currencies (so you can't add dollars to pounds)
- Timezone aware timestamps (so a time in Australia looks differet from
a time in Europe)

Probably much more.

> I would appreciate to have such system in PostgreSQL.
>
> Do you think, it is feasible ? unrealistic ?
> Any comment ?

I think it is definitly feasable. There's been discussion before. I
think the best way syntax-wise would be to extend the type system
generically to have subtypes. For example currency(gbp) and siunit(A).
This would simplify operators. You could create a simple add operator
that checked the subtype and complained if they didn't match. A
multiply operator for siunit might even return the appropriate derived
unit. An advanced add unit for currency might lookup an exchange rate
table.

However, I think this might be a tricky (but very worthwhile) project.
Maybe create a subtypes table with the columns (oid, supertypeid,
subtypename) and use the oid here to identify the subtype in storage.
To be complete it would need to change:

- The parser to idenify the new type definitions
- pg_dump to dump these types
- input/output functions for these types
- handle storage

But with a bit of work it could be a nice project.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Pailloncy Jean-Gerard
Date:
Subject: Extended unit
Next
From: Terry Lee Tucker
Date:
Subject: Re: disable trigger from transaction