Databases :: MySql :: What data type should I use |
|||
| By: jayrod |
Date: 21/04/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
I've got a script that will import email text into a database. right now i'm just using a varchar255 field to hold it. What I'd like to know is there a better data format to use? one that will allow me to perform like searches on? I'm hoping to store it in a huge field and do something like this. select * from table where email_body like %$some_string% or where table contains some combination of strings. |
|||
| By: TheFalklands | Date: 21/04/2003 13:03:00 | Type : Comment |
|
| I think the best fiend type is text.(Cos that you may need to save more than 255 characters). |
|||
| By: VGR | Date: 21/04/2003 15:31:00 | Type : Answer |
|
| yes, TEXT seems appropriate, BUT you'll need to rely on the infamous FULLTEXT index type, and will be limited to 2+ to 5+ characters-long words and never search for 'someword' liek this : LIKE '%someword%', because for example searching for 'men' will return 'refreshment', 'amendment', 'women'... |
|||
| By: jayrod | Date: 22/04/2003 20:20:00 | Type : Comment |
|
| actually I'd like the search for men to pull back refreshment. is there any other searching mechanisms I can use? Thanks |
|||
| By: VGR | Date: 22/04/2003 20:38:00 | Type : Comment |
|
| yes. I'm working on this right now for a client. You could try a very fast solution by trying this : select * from yourtable where yourfield LIKE 'men %' or yourfield LIKE '% men' or yourfield LIKE '% men %' or yourfield LIKE '% men\'%' or yourfield LIKE '%\'men %'; don't worry, the expression is evaluated only once ;-) |
|||
| By: Ice_S5 | Date: 22/04/2003 21:32:00 | Type : Comment |
|
| What about: SELECT * FROM your_table WHERE your_field RLIKE '[[:<:]]men[[:>:]]' IMHO it works. |
|||
| By: jayrod | Date: 22/04/2003 21:36:00 | Type : Comment |
|
| Ok let me try a few of those queries and I'll grade one as the answer. Thank you for the input |
|||
| By: VGR | Date: 22/04/2003 21:53:00 | Type : Comment |
|
| try to avoid REGEXP call, they are particlularly inefficient 8-) on what I work right now : WHERE REGEXP("...") : 429ms WHERE CONCAT() LIKE ...(multiple LIKEs) : 47ms WHERE ... MATCH ('...') [fulltext] : 6ms with proper index |
|||
| By: jayrod | Date: 22/04/2003 21:56:00 | Type : Comment |
|
| explain the match statement... i'm green to database design btw |
|||
| By: VGR | Date: 22/04/2003 22:11:00 | Type : Comment |
|
| ALTER TABLE yourtablename ADD FULLTEXT (field1); SELECT * FROM yourtable WHERE MATCH(field1) AGAINST('thevalue'); see MySql doc at <A HREF="http://www.mysql.com">www.mysql.com</a>, type in "fulltext" in the search box |
|||
| By: jayrod | Date: 26/04/2003 14:06:00 | Type : Comment |
|
| I went with full text.. thanks |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








