X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id BD12D9FA140 for ; Sat, 1 Jul 2006 10:48:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 22692-03 for ; Sat, 1 Jul 2006 10:48:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by postgresql.org (Postfix) with ESMTP id 4F69B9FA395 for ; Sat, 1 Jul 2006 10:48:01 -0300 (ADT) Received: from lythanhphu ([66.130.229.163]) by VL-MO-MR003.ip.videotron.ca (Sun Java System Messaging Server 6.2-2.05 (built Apr 28 2005)) with ESMTP id <0J1Q008MD8ZX7M90@VL-MO-MR003.ip.videotron.ca> for pgsql-sql@postgresql.org; Sat, 01 Jul 2006 09:47:58 -0400 (EDT) Date: Sat, 01 Jul 2006 09:47:59 -0400 From: Daniel CAUNE Subject: Constraint UNIQUE on a column not case sensitive To: pgsql-sql@postgresql.org Message-id: <0J1Q008ME8ZX7M90@VL-MO-MR003.ip.videotron.ca> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Mailer: Microsoft Office Outlook, Build 11.0.6353 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 7BIT Thread-index: AcadFPZ+cCBofkzMSwOynUgrJR4khA== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/4 X-Sequence-Number: 25578 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