pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel CAUNE <d.caune@free.fr>
To: pgsql-sql@postgresql.org
Subject: Constraint UNIQUE on a column not case sensitive
Date: Sat, 01 Jul 2006 09:47:59 -0400
Message-ID: <0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca> (raw)

Hi,

I would like to find an efficient solution for adding/implementing a constraint UNIQUE on a VARCHAR column not case sensitive:

ALTER TABLE MyTable
 ADD CONSTRAINT UNQ_MyTable_MyColumn
      UNIQUE (lower(MyColumn));       -- invalid syntax

The idea is to have an index on that column, in a not case sensitive form, i.e. lower(MyColumn).

SELECT *
  FROM MyTable
  WHERE lower(MyColumn) = lower('...');

I don't know how to add such a constraint on MyTable except by defining a trigger on INSERT clause and checking whether lower(:NEW.MyColumn) has been already inserted in MyTable.

Is there better and more efficient way to do that?

Regards,


--
Daniel




view thread (4+ messages)  latest in thread

Message-ID: <0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca>
Permalink:  ../0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca/
Also on:    postgresql.org/message-id/0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca

 · 

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: d.caune@free.fr
  Subject: Re: Constraint UNIQUE on a column not case sensitive
  In-Reply-To: <0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca>

* 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