On Fri, Aug 26, 2005 at 13:04:10 +1000,
> Desired Outcome(s):
> * I would like to have the convenience of declaring a column that obeys
> a constraint (similar to using a domain), but allows a "tidy-up" as the
> value is created BEFORE asserting the constraint. This *might* be
> termed a "domain trigger". (Perhaps even a WORM is possible!).
> * I would like to able to declare columns as
> "trimmed_varchar(n)".
> * I'd like to be able to use the same approach for other "weak domains".
>
> Question(s):
> * Am I being realistic, or should I grit my teeth and clone code from
> trigger to trigger and column to column?
> * Is this something I should try and do using domains, types and
> cast functions from "text" or some horrible combination of them all?
> * Has anybody got a code sample that might do something similar.
I think it is normal to expect the application to pass you clean data.
I think you can do what you want by creating a new type. I seem to remember
there are issues with creating whatever(n) types (my memory is that varchar(n)
is hardwired into the parser), but certainly you could make an alternate
version of text whose input function trimmed leading and trailing whitespace.
You could also create casts between this new type and text if you needed
that ability as well.