X-Original-To: pgsql-admin@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D1B73475458 for ; Tue, 18 Feb 2003 13:07:24 -0500 (EST) Received: from localhost.localdomain (unknown [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id 2BDE5475AFA for ; Tue, 18 Feb 2003 13:07:21 -0500 (EST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.5/8.12.5) with ESMTP id h1IIXq6P029286; Tue, 18 Feb 2003 13:33:55 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h1IJ77p15990; Tue, 18 Feb 2003 14:07:09 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id CWVL1SKH; Tue, 18 Feb 2003 13:06:57 -0500 Subject: Re: uppercase = lowercase From: Robert Treat To: Donald Fraser Cc: "[ADMIN]" In-Reply-To: <00b301c2d6cf$36ba0450$1664a8c0@DEMOLITION> References: <00b301c2d6cf$36ba0450$1664a8c0@DEMOLITION> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 18 Feb 2003 13:07:07 -0500 Message-Id: <1045591627.12931.898.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/294 X-Sequence-Number: 7492 We get this question a lot, usually from folks converting from mysql. Do any of the core folks think this is worth adding to contrib? Or perhaps a project on gborg would be more appropriate? Robert Treat On Mon, 2003-02-17 at 16:54, Donald Fraser wrote: > In my opinion there are no usefull solutions for this unless you always > use single column indexing. > For example: > SELECT * FROM mytable WHERE lower(mycolumn) <= 'mycondition' ORDER BY > lower(mycolumn); > will give case insensitive ordering and if you want it to use an index > for perfomance then you need to create a function index such as: > CREATE INDEX myindex ON mytable USING btree (lower(mycolumn)); > That's fine for single column ordering but beyond that you have to > create custom functions to combine multiple columns into one data type. > For example you cannot create an index like: > CREATE INDEX myindex ON mytable USING btree (lower(mycolumn), > lower(mysecondcolumn)); > But you can create: > CREATE INDEX myindex ON mytable USING btree (myfunction(mycolumn, > mysecondcolumn)); > This is when I think it is not useful because quite often you need more > than one column for indexing and you don't want to have to be creating > an assortment of custom functions for every combination of column type > you might choose. > > What I have done is to create a new data type called citext (case > insensitive text) which stores and retrieves data exactly as text type > does but when it comes to operators such as >,<,>=,<= and = it uses case > insensitive comparisons. > All my problems were solved, no more having to type lower() all over the > place, making custom functions for multiple column indexing etc... > I have attached the source code, which can be built in the normal > "contrib" fashion for anyone interested. > To save opening the zip file to find out whether it's of interest I have > included the readme file contents. > If anyone thinks it is worth adding to the "contrib" for the general > public please do so. > > Here's the contents of the readme file: > =============================================================== > Module citext created by Donald Fraser. > First release to public: 17th Feb. 2003. > Files: citext.c, Makefile, citext.sql, readme.citext > This module was created to implement a Case-Insensitive text data type > named citext. > citext uses the same storage (input and output) as text and is therefore > totally > compatible with any existing functions that use the text data type. For > this reason > I used function over-loading on most of the in-built functions that take > text > parameters. > citext only supports btree for indexing. > citext is not as efficient as text because the operator functions > (<,<=,=,>=,>) and > the btree compare function will make copies of the data and convert it > to lower case > for comparisons. There is room here for optimisations so that data isn't > copied > unnecessarily, but as a first attempt no major optimisations were > considered. > You can type cast citext into any of the data types that you can > type-cast text into > including of course text. > The in-built functions that were not over-loaded to take citext are: > split_part, position, quote_ident, quote_literal, replace, translate, > substr, > strpos, timezone. You can use these with a cast if you really want (Some > of the > substr functions were over-loaded but not all). > Regular expressions: > Because the data type is inherently case-insensitive many of the regular > expressions > produce the same result. > That is ~ and ~* are the same as is: > !~ and !~* > ~~ and ~~* > !~~ and !~~* > I had to make a decision on casting between types for regular > expressions and decided > that if any parameter is of citext type then case insensitive applies. > For example > applying regular expressions with a varchar and a citext will produce a > case- > insensitive result. > Having thought about this afterwards I realised that since we have the > option to use > case-insensitive results with regular expressions I should have left the > behaviour > exactly as text and then you have the best of both worlds... oh well not > hard to > change for any of you perfectionists! > Installation: > make install > run the sql scrip in file citext.sql, for example: > psql -d template1 -f citext.sql -o citext.out postgres > ================================================================= > > ----- Original Message ----- > From: "jose antonio leo" < > jaleo8@storelandia.com> > To: < pgsql-admin@postgresql.org> > Sent: Friday, February 14, 2003 8:51 AM > Subject: [ADMIN] uppercase = lowercase > > > > Hi!! > > How can I make selects not sensitive uppercase and lowercase characters? > This is possible modifying something of psql configuration? > > Thanks >