MySQL Forums
Forum List  »  General

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

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.