Received: from astrid2.nic.fr (astrid2.nic.fr [192.134.4.2]) by postgresql.org (Postfix) with ESMTP id E6A7747587E for ; Wed, 10 Jul 2002 09:33:35 -0400 (EDT) Received: from vespucci.nic.fr (postfix@vespucci.nic.fr [192.134.4.68]) by astrid2.nic.fr (8.9.1/jtpda-5.3.1) with ESMTP id PAA04865 for ; Wed, 10 Jul 2002 15:33:39 +0200 (MET DST) Received: by vespucci.nic.fr (Postfix, from userid 1000) id 97E02102F5; Wed, 10 Jul 2002 15:33:39 +0200 (CEST) Date: Wed, 10 Jul 2002 15:33:39 +0200 From: Stephane Bortzmeyer To: pgsql-general@postgresql.org Subject: Re: Disabling case sensitivity Message-ID: <20020710133339.GA16235@nic.fr> References: <20020710132200.GA3558@feivel.credativ.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020710132200.GA3558@feivel.credativ.de> User-Agent: Mutt/1.3.28i Organization: NIC France X-URL: http://www.nic.fr/ X-Operating-System: Debian GNU/Linux 3.0 X-Kernel: Linux 2.4.18-686 i686 X-Archive-Number: 200207/529 X-Sequence-Number: 27016 On Wed, Jul 10, 2002 at 03:22:00PM +0200, Michael Meskes wrote a message of 31 lines which said: > Can't you use something like > > SELECT from table where tolower(username)='good'; If you want sometimes case-sensitive comparison and sometimes not, it is a good solution (the PostgreSQL extension ILIKE is another). But if you want to "disable case-sensitivity", you risk that some applications forget the call to tolower(). Therefore, I prefer to create a trigger which will force the field to lowercase before INSERTing it. (The problem of my solution is that it is no longer case-preserving.) CREATE FUNCTION force_lower_case() RETURNS OPAQUE AS 'BEGIN NEW.name = lower(NEW.name); RETURN NEW; END;' LANGUAGE PLPGSQL; -- Domain names are only in US-ASCII (so no locale problems) and are -- case-insensitive. If you want to record the original case, add a -- new field. CREATE TRIGGER force_lower_case BEFORE INSERT ON Domains FOR EACH ROW EXECUTE PROCEDURE force_lower_case();