X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2BF62D6E40 for ; Fri, 26 Aug 2005 00:40:03 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20164-10 for ; Fri, 26 Aug 2005 03:39:57 +0000 (GMT) Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [192.108.102.143]) by svr1.postgresql.org (Postfix) with ESMTP id 2FB3FD76AF for ; Fri, 26 Aug 2005 00:39:56 -0300 (ADT) Received: from [172.16.1.182] glaesema [61.197.227.146] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 1.6 $ on Linux via secured & encrypted transport (TLS); Thu, 25 Aug 2005 21:39:56 -0600 In-Reply-To: <200508261304.10542.dave.bath@unix.net> References: <200508261304.10542.dave.bath@unix.net> Mime-Version: 1.0 (Apple Message framework v734) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Cc: postgresql sql list Content-Transfer-Encoding: quoted-printable From: Michael Glaesemann Subject: Re: Tidying values on variable instantiation Date: Fri, 26 Aug 2005 12:39:52 +0900 To: dave.bath@unix.net X-Mailer: Apple Mail (2.734) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.027 required=5 tests=[AWL=0.027] X-Spam-Level: X-Archive-Number: 200508/245 X-Sequence-Number: 22473 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 =20 > obeys > a constraint (similar to using a domain), but allows a "tidy-up" =20 > 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 =20 > domains". Unfortuantely, I don't know of a way to obtain your desired outcomes, =20= but perhaps can offer a couple of ideas that you haven't mentioned =20 (though you may have already thought of them and discarded them as =20 undesireable. In that case, my apologies :) Perhaps rather doing this with a trigger and having the table take =20 care of it, you could use pl functions to handle the inserts, so =20 instead of using INSERT directly, you could call the =20 insert_into_table_foo function. The insert_into_table_foo function =20 would clean up the input and then call INSERT. A disadvantage of this =20= is that you'll need to write one of these for each table, though =20 there are some who handle a lot of their inserts, updates, etc, via =20 pl functions rather than calling the INSERT and UPDATE commands =20 directly. Another option would be to have a separate cleaning function (e.g., =20 clean_foo() )for each "type" you want, and then call it with =20 something like INSERT INTO bar (baz, bat, foo) values (232, =20 '2005-02-20', clean_foo('protofoo')); This has the advantage that you =20= just need to write one function for each type (rather than each =20 table), but you'll have to remember to call it. While I can understand your motivation, I personally think this kind =20 of operation is best left in the application layer (which includes =20 such insert functions) rather than the DDL. Just my =A52. Michael Glaesemann grzm myrealbox com