MySQL Forums :: General :: Unique Constraint Using My Own Definition of "Equals"


Advanced Search

Unique Constraint Using My Own Definition of "Equals"
Posted by: B C ()
Date: March 06, 2009 12:30AM

I have a column that contains characters. I would like to put a unique constraint on this column, using my own definition of "equal."

Here's what I mean. In my data, two values are equal if they differ only by white space or capitalization. For example:

abcdefg == ABCdEfG == A B CDEFG == abCDefG ... (you get the idea)

My goal is that the database should reject any new rows where this column already contains an "equal" value.

Currently, I am working around this problem by using PHP to remove white space and case information before the data gets inserted. Then, a typical unique constraint does the job of rejecting duplicates. But of course enforcing integrity constraints at the application level is bad design, and I lose the original user-input representation of the data.

How can I get MySQL to enforce this constraint?

- Bill

Options: ReplyQuote


Subject Written By Posted
Unique Constraint Using My Own Definition of "Equals" B C 03/06/2009 12:30AM
Re: Unique Constraint Using My Own Definition of "Equals" Peter Brawley 03/06/2009 11:21AM
Re: Unique Constraint Using My Own Definition of "Equals" B C 03/06/2009 12:33PM
Re: Unique Constraint Using My Own Definition of "Equals" Rick James 03/07/2009 06:29PM
Re: Unique Constraint Using My Own Definition of "Equals" B C 03/07/2009 10:16PM
Re: Unique Constraint Using My Own Definition of "Equals" Rick James 03/07/2009 11:55PM
Re: Unique Constraint Using My Own Definition of "Equals" B C 03/08/2009 01:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.