| From: | Kenneth Marshall <ktm(at)rice(dot)edu> | 
|---|---|
| To: | Phillip Smith <phillip(at)softworks(dot)com> | 
| Cc: | pgsql-novice(at)postgresql(dot)org | 
| Subject: | Re: Collation and Case Insensitivity | 
| Date: | 2011-01-13 15:11:27 | 
| Message-ID: | 20110113151127.GP5474@aart.is.rice.edu | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-novice | 
On Thu, Jan 13, 2011 at 02:33:46PM -0000, Phillip Smith wrote:
> Hi,
>  
> Im moving over from MS SQL. I've been googling this for ages now and suprisingly cannot find a clear answer.
>  
> I want my data in tables to be case insensitive.
>  
> This is so i can:
>  
> 1. Put keys on natural key fields, for instance a product part number. I product number 'ABC123' inserted i need to disallow 'abc123' to be inserted as a second row. Please don't tell me i have to add another column holding a lowered version of the product number. My database is littered with this need and i would end up bloating my table schema.
>  
> 2.  I need to query case insensitively. SELECT * FROM product WHERE product_number = 'ABC123' should return the same row as SELECT * FROM product WHERE product_number = 'abc123'
>  
> Is there a database wide collation setting i can make. There are lots of online posts regarding using LOWER function for querying. This is a workaround for point (2) but does not remedy point (1) above.
>  
> Many thanks
>  
> Phillip
>  
> Phillip Smith
There is a citext module that may help:
http://www.postgresql.org/docs/9.0/static/citext.html
Alternatively, you could use a trigger on INSERT/UPDATE to
automatically lower() the incoming data which would allow
(2) to work.
Regards,
Ken
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Susanne Ebrecht | 2011-01-14 14:20:48 | Re: Collation and Case Insensitivity | 
| Previous Message | Phillip Smith | 2011-01-13 14:33:46 | Collation and Case Insensitivity |