pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: How can unique columns being case-insensitive be accomplished?
2+ messages / 2 participants
[nested] [flat]

* Re: How can unique columns being case-insensitive be accomplished?
@ 2002-09-16 13:38 Tom Lane <tgl@sss.pgh.pa.us>
  2002-09-16 15:09 ` Re: How can unique columns being case-insensitive be accomplished? Ross J. Reedstrom <reedstrm@rice.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: Tom Lane @ 2002-09-16 13:38 UTC (permalink / raw)
  To: J rg <mail2holly@gmx.de>; +Cc: pgsql-sql

"Jörg" <mail2holly@gmx.de> writes:
> How can this problem be overcome? Any ideas?

Create a unique index on lower(name).

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: How can unique columns being case-insensitive be accomplished?
  2002-09-16 13:38 Re: How can unique columns being case-insensitive be accomplished? Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-09-16 15:09 ` Ross J. Reedstrom <reedstrm@rice.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Ross J. Reedstrom @ 2002-09-16 15:09 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org, J366rg <mail2holly@gmx.de>

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-09-16 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-09-16 13:38 Re: How can unique columns being case-insensitive be accomplished? Tom Lane <tgl@sss.pgh.pa.us>
2002-09-16 15:09 ` Ross J. Reedstrom <reedstrm@rice.edu>

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