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. It's all record_in but it's not working for me: # CREATE TYPE measurement AS (value float, units text); CREATE TYPE # select '(5,a)'::measurement; ERROR: Cannot cast type "unknown" to measurement # select measurement(5,'a'); ERROR: Function measurement(integer, "unknown") does not exist Unable to identify a function that satisfies the given argument types You may need to add explicit typecasts # select cast( (5,'a') as measurement); ERROR: parser: parse error at or near "as" at character 22 # select cast( '5' as measurement); ERROR: Cannot cast type "unknown" to measurement This is 7.3 though, is it better in later versions? I can't find any examples anywhere. Composite types don't seems to be used much. However, it appears you could just update pg_type to change the input/output functions... > The argument that we should extend the type system for this would become > a lot more credible if there were a widely-used extension in existence > for it to prove that there's sufficient demand. I guess it's mostly syntactic sugar, but it might normalize the varchar(n) and timestamp(n) format. Have a nice day, -- Martijn van Oosterhout <kleptog@xxxxxxxxx> 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:
pgp4ZmegYtCYq.pgp
Description: PGP signature