Re: Extended unit - Mailing list pgsql-general

From Tom Lane
Subject Re: Extended unit
Date
Msg-id 6989.1106688419@sss.pgh.pa.us
Whole thread Raw
In response to Re: Extended unit  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Martijn van Oosterhout <kleptog@svana.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

pgsql-general by date:

Previous
From: John DeSoi
Date:
Subject: Re: Postgresql, SQL server and Oracle. Please, help
Next
From: Tom Lane
Date:
Subject: Re: EMBEDDED PostgreSQL