Alternate input for user defined data type

From: Aram Fingal <fingal(at)multifactorial(dot)com>
To: Postgres-General General <pgsql-general(at)postgresql(dot)org>
Subject: Alternate input for user defined data type
Date: 2013-08-20 20:11:43
Message-ID: A252EAE6-944F-44A5-9D9B-0CCE188AD9DC@multifactorial.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message andres.pascal 2013-08-20 23:06:08 Re: Fastest Index/Algorithm to find similar sentences
Previous Message Tom Lane 2013-08-20 20:03:08 Re: pg_extension_config_dump() with a sequence