pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Glaesemann <grzm@myrealbox.com>
To: dave.bath@unix.net
Cc: postgresql sql list <pgsql-sql@postgresql.org>
Subject: Re: Tidying values on variable instantiation
Date: Fri, 26 Aug 2005 12:39:52 +0900
Message-ID: <C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com> (raw)
In-Reply-To: <200508261304.10542.dave.bath@unix.net>
References: <200508261304.10542.dave.bath@unix.net>


On Aug 26, 2005, at 12:04 PM, Bath, David wrote:

> 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".


Unfortuantely, I don't know of a way to obtain your desired outcomes,  
but perhaps can offer a couple of ideas that you haven't mentioned  
(though you may have already thought of them and discarded them as  
undesireable. In that case, my apologies :)

Perhaps rather doing this with a trigger and having the table take  
care of it, you could use pl functions to handle the inserts, so  
instead of using INSERT directly, you could call the  
insert_into_table_foo function. The insert_into_table_foo function  
would clean up the input and then call INSERT. A disadvantage of this  
is that you'll need to write one of these for each table, though  
there are some who handle a lot of their inserts, updates, etc, via  
pl functions rather than calling the INSERT and UPDATE commands  
directly.

Another option would be to have a separate cleaning function (e.g.,  
clean_foo() )for each "type" you want, and then call it with  
something like INSERT INTO bar (baz, bat, foo) values (232,  
'2005-02-20', clean_foo('protofoo')); This has the advantage that you  
just need to write one function for each type (rather than each  
table), but you'll have to remember to call it.

While I can understand your motivation, I personally think this kind  
of operation is best left in the application layer (which includes  
such insert functions) rather than the DDL.

Just my ¥2.

Michael Glaesemann
grzm myrealbox com





view thread (7+ messages)  latest in thread

Message-ID: <C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com>
Permalink:  ../C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com/
Also on:    postgresql.org/message-id/C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: grzm@myrealbox.com, dave.bath@unix.net
  Subject: Re: Tidying values on variable instantiation
  In-Reply-To: <C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com>
  References: <200508261304.10542.dave.bath@unix.net> <C8075EED-E822-4372-928C-31C3C6DD6C3B@myrealbox.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox