Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F066D476094 for ; Mon, 16 Sep 2002 11:09:44 -0400 (EDT) Received: from ece.rice.edu (ece.rice.edu [128.42.4.34]) by postgresql.org (Postfix) with ESMTP id 79959475F13 for ; Mon, 16 Sep 2002 11:09:44 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by ece.rice.edu (Postfix) with ESMTP id 2A39068A6B; Mon, 16 Sep 2002 10:09:49 -0500 (CDT) Received: from wallace.ece.rice.edu (wallace.ece.rice.edu [128.42.12.154]) by ece.rice.edu (Postfix) with ESMTP id 6BF5F68A5E; Mon, 16 Sep 2002 10:09:48 -0500 (CDT) Received: from reedstrm by wallace.ece.rice.edu with local (Exim 3.34 #1 (Debian)) id 17qxVU-0000Lo-00; Mon, 16 Sep 2002 10:09:48 -0500 Date: Mon, 16 Sep 2002 10:09:48 -0500 From: "Ross J. Reedstrom" To: pgsql-sql@postgresql.org, J366rg Subject: Re: How can unique columns being case-insensitive be accomplished? Message-ID: <20020916150948.GA797@rice.edu> Mail-Followup-To: "Ross J. Reedstrom" , pgsql-sql@postgresql.org, J366rg References: <26275.1032183526@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=unknown-8bit Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <26275.1032183526@sss.pgh.pa.us> User-Agent: Mutt/1.3.27i X-Virus-Scanned: by AMaViS snapshot-20020300 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/179 X-Sequence-Number: 9456 On Mon, Sep 16, 2002 at 09:38:46AM -0400, Tom Lane wrote: > "Jörg" writes: > > How can this problem be overcome? Any ideas? > > Create a unique index on lower(name). I'm sure Jörg can follow this tip, but for the archives, I'll include the full syntax: CREATE UNIQUE INDEX drug_lwr_idx ON drug ( lower(name) ) Another trick would be to use your trigger to lower() the inserted/updated names, rather than only as a test, combined with a regular unique index: CREATE FUNCTION lower_drug () RETURNS OPAQUE AS ' BEGIN NEW.name = lower(NEW.name); RETURN NEW; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER drug_insert BEFORE UPDATE OR INSERT ON drug FOR EACH ROW EXECUTE PROCEDURE lower_drug(); That keeps your data nice and clean and consistent, otherwise the first time a MixedCaseDrugName goes in, it'll keep the correct 'mixedcasedrugname' from being inserted, later. Be very sure that lower() gives you exactly the output you want, however. Ross