Re: Extended unit
От | Tom Lane |
---|---|
Тема | Re: Extended unit |
Дата | |
Msg-id | 6989.1106688419@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: Extended unit (Martijn van Oosterhout <kleptog@svana.org>) |
Список | 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 по дате отправления: