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 C4113D7A48 for ; Fri, 26 Aug 2005 12:20:53 -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 16486-07 for ; Fri, 26 Aug 2005 15:20:52 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id B5960D7A2F for ; Fri, 26 Aug 2005 12:20:51 -0300 (ADT) Received: (qmail 17724 invoked by uid 500); 26 Aug 2005 15:20:27 -0000 Date: Fri, 26 Aug 2005 10:20:27 -0500 From: Bruno Wolff III To: "Bath, David" Cc: pgsql-sql@postgresql.org Subject: Re: Tidying values on variable instantiation Message-ID: <20050826152027.GB16546@wolff.to> Mail-Followup-To: Bruno Wolff III , "Bath, David" , pgsql-sql@postgresql.org References: <200508261304.10542.dave.bath@unix.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200508261304.10542.dave.bath@unix.net> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/248 X-Sequence-Number: 22476 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.