Re: VARCHAR: Working to design, but why?
Posted in 1998
Leonid Belov wrote: > > Fred Prose wrote: > > > According to the SQL Reference manual: > > > > "When you store a VARCHAR calue in the database, only its defined characters > > are stored. The database does not strip a VARCHAR object of any > > user-entered trailing blanks, nor does the database server pad the VARCHAR > > to the full length of the column." > > > > The question is, why would the design be that way -- ie. the trailing > > blanks not stipped if the equivalent of "ABC " is entered. I've > > never worked with a product that made that decision. The reason is that the SQL-92 standard defines it this way. Don't you prefer to be in control of your strings? Use CHAR to get blank padding, use VARCHAR to get no blank padding. Simple. To get fixed-length padded strings out of VARCHAR is trickier unless you have the functions in 7.3. A stored procedure will do it. > > > > A test case also showed that if you alter a table and change a column from > > CHAR(20) to VARCHAR(20) you get the entire VARCHAR(20) padded. > > I think that server must not edit character data entered by user in any way > and must store data "as-is". > If you want to strip leading/trailing blanks you can TRIM string > > Leonid -- <HR> Peter Lancashire Information Systems Specialist, Bayer plc Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK Tel: +44-1635-562258, Fax: +44-1635-562281 <HR> If all else fails, read the instructions and the release notes. Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/ <HR>