Re: Case Insensitive Data Type

Поиск
Список
Период
Сортировка
От Russell Black
Тема Re: Case Insensitive Data Type
Дата
Msg-id 064601c20345$a324f450$0464a8c0@iarchives.com
обсуждение исходный текст
Ответ на Case Insensitive Data Type  ("Russell Black" <russell.black@iarchives.com>)
Ответы Re: Case Insensitive Data Type  (Neil Conway <nconway@klamath.dyndns.org>)
Список pgsql-general
I found this method in the archives:
 
CREATE TABLE t1 (f1 varchar(40));
CREATE INDEX t1_f1_idx ON t1 (lower(f1));
SELECT * FROM t1 WHERE lower( f1 ) = 'whatever';
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 * FROM t1 WHERE f1 = 'whatever';
Instead of
SELECT * 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.
Any ideas?
 
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 по дате отправления:

Предыдущее
От: Doug Fields
Дата:
Сообщение: Efficiency question: VARCHAR with empty string vs NULL
Следующее
От: Fran Fabrizio
Дата:
Сообщение: Re: Case Insensitive Data Type