Re: Alternate input for user defined data type

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Aram Fingal *EXTERN*" <fingal(at)multifactorial(dot)com>, "Postgres-General General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Alternate input for user defined data type
Date: 2013-08-21 07:08:54
Message-ID: A737B7A37273E048B164557ADEF4A58B17C078B0@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Aram Fingal wrote:
> I want to create a user defined data type but have flexible input just like, for example, the boolean
> data type where TRUE can be entered as any of (TRUE, true, T, t, YES, yes, Y, y, 1...) and it will be
> interpreted as the same thing.
>
> So suppose I have days of the week:
>
> CREATE TYPE days_of_week AS ENUM ('Su','M','Tu','W','Th','F','Sa');
>
> Except that I want 'MON', 'Mon', 'mon' and 'monday' all to be interpreted as 'M' in the data type.
> What is the best way to do this.? Is that what input_function is for in the CREATE TYPE command? Do I
> need to create a trigger?

Yes, the type input function converts the string representation to the internal
representation, so that's where you'd implement that in a user defined data type.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Kane 2013-08-21 09:09:50 Re: Convincing the query planner to play nice
Previous Message Alisa 2013-08-21 05:22:49 Re: thank you