Re: Extended unit

From: Pailloncy Jean-Gerard <jg(at)rilk(dot)com>
To: Postgres mailing list general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Extended unit
Date: 2005-01-28 01:04:50
Message-ID: a87079575cec588dc0d2984173c84113@rilk.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Some word from my test work.

I try first to just have a parser that can manage a string of unit.
like 'm s-1 kg2.5 A3.5/7.2'
The parser accept :
- any letters for the unit
- a + or - or nothing before the power
- a fractional power
- the unit separator is space ;-/
The system normalize the fraction of the power.

select ('1 m'::text + '1 m'::text)::text
'2 m'
select ('1 m'::text - '1 m'::text)::text
'0 m'
select ('1 m'::text / 2)::text
'0.5 m'
select ('1 m'::text * 2)::text
'2 m'
select ('1 m'::text + 2)::text
'NULL'
select ('1 m'::text * '3 s'::text)::text
'3 s m'
select ('1 m'::text / '3 s'::text)::text
'0.333333333333333 s-1 m'
select ('1 m'::text + '3 s'::text)::text
'NULL'
select (1 / '3 s'::text)::text
'0.333333333333333 s-1'
select ('1 m s2 m s kg'::text::doubleunit)::text
'1 s3 m2 kg'
select ('4.5 m s2 m-3.2/7.1 s'::text::doubleunit)::text
'4.5 s3 m39/71'

So with this system you can add with unit checking any value.
But there is no conversion.
So I need to enter all unit in a coherent system.
I have begin to add a translation table for unit.
The first table will to manage affix only (kilo, mega, giga, micro,
milli, etc.)

The may problem is because is done at execution time, it is 50 times
slower that standard calculus.

Note: I use too much ::text because I mix som CAST definition ;-(

I really want it at parsing time....

Note 2: I think version 8.0 has a better support for function returning
composite type. It would be easier to build the system, when I'll
upgrade...

Cordialement,
Jean-Gérard Pailloncy

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-01-28 01:23:05 Re: changing sort_mem on the fly?
Previous Message Jim C. Nasby 2005-01-28 00:23:21 Re: changing sort_mem on the fly?