From: Martijn Tonies Date: September 11 2006 6:13pm Subject: Re: Varchar mystery List-Archive: http://lists.mysql.com/mysql/201771 Message-Id: <006b01c6d5cd$ee6c1330$cd02a8c0@martijnws> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > I'm using MySQL Linux version 4.1.21 standard. > > I have a table with fields of a variety of types, including varchar(255) and > text (which might matter). When I do > > SELECT MAX(LENGTH(x)) FROM tx; > > where x is a varchar(255), I get back 266 as the result of the query! > > This isn't listed as one of the silent conversions - varchar(256) would be > converted to text, but not varchar(255). What's going on? Well, LENGTH returns the length in bytes, not characters. If you use characterset in your table/column that uses a multi-byte-per-character encoding scheme, LENGTH can return more than the number of characters. See also CHAR_LENGTH here: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html Martijn Tonies Database Workbench - development tool for MySQL, and more! Upscene Productions http://www.upscene.com My thoughts: http://blog.upscene.com/martijn/ Database development questions? Check the forum! http://www.databasedevelopmentforum.com