Case Insensitive Data Type

Поиск
Список
Период
Сортировка
От Russell Black
Тема Case Insensitive Data Type
Дата
Msg-id 061801c20342$881c8310$0464a8c0@iarchives.com
обсуждение исходный текст
Ответы Re: Case Insensitive Data Type  (Darren Ferguson <darren@crystalballinc.com>)
Re: Case Insensitive Data Type  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
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 по дате отправления:

Предыдущее
От: Moritz Sinn
Дата:
Сообщение: Re: user defined variables
Следующее
От: merlyn@stonehenge.com (Randal L. Schwartz)
Дата:
Сообщение: [meta] complaint email addr when news.postgresql.org is down?