pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ross J. Reedstrom <reedstrm@rice.edu>
To: pgsql-sql@postgresql.org, J366rg <mail2holly@gmx.de>
Subject: Re: How can unique columns being case-insensitive be accomplished?
Date: Mon, 16 Sep 2002 10:09:48 -0500
Message-ID: <20020916150948.GA797@rice.edu> (raw)
In-Reply-To: <26275.1032183526@sss.pgh.pa.us>
References: <alsac7$30gc$1@news.hub.org>
	<26275.1032183526@sss.pgh.pa.us>

On Mon, Sep 16, 2002 at 09:38:46AM -0400, Tom Lane wrote:
> "Jörg" <mail2holly@gmx.de> 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



view thread (2+ messages)

Message-ID: <20020916150948.GA797@rice.edu>
Permalink:  ../20020916150948.GA797@rice.edu/
Also on:    postgresql.org/message-id/20020916150948.GA797@rice.edu

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: reedstrm@rice.edu, mail2holly@gmx.de
  Subject: Re: How can unique columns being case-insensitive be accomplished?
  In-Reply-To: <20020916150948.GA797@rice.edu>

* 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