Community Documentation

MySQLism: use TEXT values and not VARCHAR(255)

Last updated February 16, 2010. Created by grub3 on February 16, 2010.
Log in to edit this page.

When inserting TEXT into a VARCHAR(255), MySQL trims the value to the first 255 characters. PostgreSQL complains and returns an error, which the correct behavior.

Example, in the aggregator module, link is a 255 varchar and we try to insert a longer text.

INSERT INTO aggregator_item (fid, title, link, author, description, timestamp, guid) VALUES (14, 'Dette : l''inté     rêt de l''UE est de sauver les meubles', 'http://rss.nouvelobs.com/c/32262/f/437880/s/907f82f/l/0Ltempsreel0Bnouvelobs0N0Cactualites0Ceconomie0Cfinance0     Iet0Imarches0C20A10A0A20A80BOBS63130Cdette0I0Ilinteret0Ide0Ilue0Iest0Ide0Isauver0Iles0Imeubles0Bhtml0Didfx0FRSS0Ieconomie0Gxtor0FRSS0E27/story01.htm', '     ', 'Interview L''économiste Denis Clerc décrypte la chute de l''euro, des bourses mondiales et la faillite possible de la Grèce. Une crise de la dette q     ui pourrait contraindre l''UE au "fédéralisme économique".<img width=''1'' height=''1'' src=''http://rss.nouvelobs.com/c/32262/f/437880/s/907f82f/mf.gif     '' border=''0''/><div class=''mf-viral''><table border=''0''><tr><td valign=''middle''><a href="http://res.feedsportal.com/viral/sendemail2_fr.html?titl     e=Dette+%3A+l%27int%C3%A9r%C3%AAt+de+l%27UE+est+de+sauver+les+meubles&link=http%3A%2F%2Ftempsreel.nouvelobs.com%2Factualites%2Feconomie%2Ffinance_et_mar     ches%2F20100208.OBS6313%2Fdette__linteret_de_lue_est_de_sauver_les_meubles.html%3Fidfx%3DRSS_economie%26xtor%3DRSS-27" target="_blank"><img src="http://     rss.feedsportal.com/images/partagez.gif" border="0" /></a></td><td valign=''middle''><a href="http://res.feedsportal.com/viral/bookmark_fr.cfm?title=Det     te+%3A+l%27int%C3%A9r%C3%AAt+de+l%27UE+est+de+sauver+les+meubles&link=http%3A%2F%2Ftempsreel.nouvelobs.com%2Factualites%2Feconomie%2Ffinance_et_marches%     2F20100208.OBS6313%2Fdette__linteret_de_lue_est_de_sauver_les_meubles.html%3Fidfx%3DRSS_economie%26xtor%3DRSS-27" target="_blank"><img src="http://rss.f     eedsportal.com/images/bookmark.gif" border="0" /></a></td></tr></table></div><br/><br/><a href="http://da.feedsportal.com/r/63068970105/u/60/f/437880/c/     32262/s/151517231/a2.htm"><img src="http://da.feedsportal.com/r/63068970105/u/60/f/437880/c/32262/s/151517231/a2.img" border="0"/></a>', 1265729675, 'ht     tp://rss.nouvelobs.com/c/32262/f/437880/s/907f82f/l/0Ltempsreel0Bnouvelobs0N0Cactualites0Ceconomie0Cfinance0Iet0Imarches0C20A10A0A20A80BOBS63130Cdette0I     0Ilinteret0Ide0Ilue0Iest0Ide0Isauver0Iles0Imeubles0Bhtml0Didfx0FRSS0Ieconomie0Gxtor0FRSS0E27/story01.htm')

The solution is to use a TEXT and not a VARCHAR(255) when you plan to insert a long text.

Page status

No known problems

Log in to edit this page

About this page

Audience
Developers and coders

Develop for Drupal

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.