Re: Extended unit

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Alban Hertroys <alban(at)magproductions(dot)nl>, Pailloncy Jean-Gerard <jg(at)rilk(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Extended unit
Date: 2005-01-25 21:26:59
Message-ID: 6989.1106688419@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> On Tue, Jan 25, 2005 at 02:31:40PM -0500, Tom Lane wrote:
>> AFAICS this could easily be implemented as a user-defined type, along
>> the lines of
>> CREATE TYPE measurement AS (value double, units text);
>> and if you want to constrain a particular column to contain only one
>> value of units, use CHECK.

> I've tried this but I can't work out how to make it work. For composite
> types you can't specify input and output functions.

No, but as of 8.0 you don't really need them, assuming that you don't
mind some parentheses around your output.

regression=# CREATE TYPE measurement AS (value float, units text);
CREATE TYPE
regression=# select cast( (5,'a') as measurement);
row
-------
(5,a)
(1 row)

Or you can implement it as a scalar type if you really want to define
your own I/O functions.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-01-25 21:35:35 Re: EMBEDDED PostgreSQL
Previous Message John DeSoi 2005-01-25 21:20:15 Re: Postgresql, SQL server and Oracle. Please, help