X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C1D615E4077 for ; Sun, 8 Aug 2004 17:40:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52643-10 for ; Sun, 8 Aug 2004 20:40:38 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 2EC215E4248 for ; Sun, 8 Aug 2004 17:40:35 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i78KeUiG056281 for ; Sun, 8 Aug 2004 20:40:30 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i78KdWDi055878 for pgsql-sql@postgresql.org; Sun, 8 Aug 2004 20:39:32 GMT From: "Thomas Wegner" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Make a column case insensitive Date: Sun, 8 Aug 2004 22:39:29 +0200 Organization: Hub.Org Networking Services Lines: 64 Message-ID: References: <1091993235.799.15.camel@jester> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200408/52 X-Sequence-Number: 18549 I create every time i need this, a copy of this field filled out by a trigger on insert and update that holds the upper (or lower for you) value of the orginal field like this: create table "users" ( "email" varchar(255), ... "u_email" varchar(255) ... ); CREATE OR REPLACE FUNCTION "public"."user_function" () RETURNS trigger AS' BEGIN NEW."u_email" = UPPER(NEW."email"); RETURN NEW; END; 'LANGUAGE 'plpgsql'; CREATE TRIGGER "user_insert" BEFORE INSERT ON "public"."user" FOR EACH ROW EXECUTE PROCEDURE "public"."user_function"(); CREATE TRIGGER "user_update" BEFORE UPDATE ON "public"."user" FOR EACH ROW EXECUTE PROCEDURE "public"."user_function"(); and do a simple select from blabla where u_email=:email Param email = Upper(searchvalue). This speed up any case insensitive searches. --------------------------------------------- Thomas Wegner Cabrio Meter - The Weather Plugin for Trillian http://trillian.wegner24.de/cabriometer "Rod Taylor" schrieb im Newsbeitrag news:1091993235.799.15.camel@jester... > On Fri, 2004-08-06 at 11:29, Gordon Ross wrote: > > Is it possible to make a column case insensitive, without having to pepper your SELECTs with lots of lower() function calls (and forgetting to do it at times !) > > You could make yourself a set returning function to do this job -- but > that is probably just as difficult to remember when selecting data out > of the table. > > create function abc(text) returns set of tab as 'select * from tab where > col = lower($1);' language sql; > > select * from abc('sEaRcH_VaLuE'); > > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match >