Re: Case Insensitive Data Type - Mailing list pgsql-general

From Russell Black
Subject Re: Case Insensitive Data Type
Date
Msg-id 062601c20345$037262d0$0464a8c0@iarchives.com
Whole thread Raw
In response to Case Insensitive Data Type  ("Russell Black" <russell.black@iarchives.com>)
List pgsql-general
I found this method in the archives:
 
CREATE TABLE t1 (f1 varchar(40));
SELECT f1 FROM t1 WHERE lower( f1 ) = 'whatever';
CREATE INDEX t1_f1_idx ON t1 (lower(f1));
This will unfortunately not work, since I'm using CMP EJB's, and I'm not writing the SQL queries myself.  The EJB container does it for me, and it wants to do a
SELECT f1 FROM t1 WHERE f1 = 'whatever';
Instead of
SELECT f1 FROM t1 WHERE lower( f1 ) = 'whatever';
This is why I'm hoping to have the database backend take care of this with perhaps a new datatype, so that the '=' operator is case insensitive.
 
Russell
----- Original Message -----
Sent: Friday, May 24, 2002 10:46 AM
Subject: [GENERAL] Case Insensitive Data Type

I'm using email addresses as a primary key in one of my tables.  Currently, I have to ensure that the email addresses are converted to lower case before they get put into the table, and that all lookups on that field are converted to lower case before the select statement, in order to ensure that Joe@Somewhere.com is the same as joe@somewhere.com.
 
Does anyone know of a case-insensitive data type?  I'd want the following behavior:
 
/* Make the primary key be a case-insensitive data type */
CREATE TABLE foo (email CASE_INSENSITIVE_VARCHAR(50) PRIMARY KEY, name VARCHAR(50));
 
/* Insert a row with a case insensitive key */
INSERT INTO foo VALUES ('joe@somewhere.com', 'Joe');
INSERT 24751 1
 
/* A different case of an existing primary key should fail */
INSERT INTO foo VALUES ('Joe@SOMEWHERE.com', 'Joe');  
ERROR:  Cannot insert a duplicate key into unique index foo_pkey
 
/* A lookup on a different case of an existing key should be successful: */
SELECT * FROM foo WHERE email = 'Joe@SOMEWHERE.com';
       email       | name
-------------------+------
 
joe@somewhere.com | Joe
(1 row)
 
Anyone know how I can accomplish this?  Can I create a custom data type to do this?
 
Thanks, Russell
 
 

pgsql-general by date:

Previous
From: Braud Agnes
Date:
Subject: Using the EXPLAIN results
Next
From: NunoACHenriques
Date:
Subject: is there any backend (server) timeout undocumented?