Hi,

I am trying to emulate MySQL's SET type, by creating a new postgresql type.

However, is it possible to create a type that has different parameters
wherever it is used.

For instance - the varchar type takes as a parameter the max characters in
the field.  Although there is only one varchar type, it has different
properties depending on whether or not it is varchar(5) or varchar(20).

I wish to be able to declare:

bitset('LOW','MEDIUM','HIGH')  // Not sure of exact syntax

Internally stored as an int4.

The trouble is in writing the in and out functions.  They need to be able to
store a list of token names in order to recreate the comma delimited list of
tokens from the internal bitset, and vice versa...

Any help?

Thanks,

Chris

--
Christopher Kings-Lynne
Family Health Network (ACN 089 639 243)


Wed, 13 Dec 2000 13:02:17 +0800
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Creating a 'SET' type
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au> writes:
> However, is it possible to create a type that has different parameters
> wherever it is used.
> For instance - the varchar type takes as a parameter the max characters in
> the field.  Although there is only one varchar type, it has different
> properties depending on whether or not it is varchar(5) or varchar(20).

Right now, that support is hard-wired into the parser for each such type
(and there aren't many).  It might be interesting to look at what it
would take to make a generalized mechanism whereby a type name could
accept parameters, with a type-specific routine being responsible for
reducing the parameters down to a typmod value.  One problem you'd run
into, I think, is creation of parsing ambiguities --- is NUMERIC(9,2)
a type specification, or a function call?  Right now it's a type spec
because NUMERIC is a keyword in the grammar, but that won't do for an
extensible mechanism.

			regards, tom lane

Wed, 13 Dec 2000 11:55:59 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Creating a 'SET' type 