Re: varchar problem



Terry wrote:
> Geoff Berrow wrote:
>> Where have you read that? A space is just another character. If you
>> want to strip them, use trim().
>>
> From page 123 of "PHP and MySQL for Dynamic Web Sites" by Larry
> Ullman: ---------
> Heading "Char vs. Varchar"
> One primary difference between the two is that anything stored as CHAR
> will always be stored as a string the length of the column (using
> spaces to pad it). Coversely, VARCHAR strings will only be as long as
> the stored string itself.

What that's saying is that CHAR will be padded - so if you have CHAR(5) and
put in "abc", it will be stored as "abc ".

If you enter " hello " into a VARCHAR, it will store a SEVEN-character
string - the following series of characters (delimited
by -) - -h-e-l-l-o- -, because that is the string it was given.

There is nothing in that saying that leading spaces in the string saved in
the VARCHAR will be trimmed.

> - a google search yielded simular results.
>
> The filename (row[0]) is varchar and has no extra spaces.
> Some of the entries (row[3]) have leading spaces - most do not.
> Additionaly, I did not put any spaces in - why should I have to strip
> them?

How is the data being entered? If it's through a form, a user could easily
enter a leading or trailing space.

Also, how are you writing the query?

--
Tony Garcia
Web Right! Development
tony.NO@xxxxxxxxxxxxxxxxxxxxxxxxxxxx


.



Relevant Pages

  • Re: split() and string.whitespace
    ... wants to split on a set of characters but 'split' splits on a string, ... and others sometimes want to strip off a string but 'strip' strips on ... Too bad you haven't suggested this when they were designing Python ... could be used to form character set literals (`aeiou` => ...
    (comp.lang.python)
  • Re: DTS How to parse a varcharfield
    ... It returns the position of the character AFTER the nth(i.e. ... you know the positions you could update the varchar string by substituting ... returns int ... I have a table that has a varchar field called ...
    (microsoft.public.sqlserver.dts)
  • Re: DTS How to parse a varcharfield
    ... It returns the position of the character AFTER the nth(i.e. ... you know the positions you could update the varchar string by substituting ... returns int ... I have a table that has a varchar field called ...
    (microsoft.public.sqlserver.dts)
  • Re: how to easily strip CR from end of a string in bash?
    ... > Ian Giblin wrote: ... If necessary we can assume that the tail of the string ... these work if I *know* it is a dosfile and just want to strip ... the last character, but if I don't know, it may break the file. ...
    (comp.unix.shell)
  • Stripping a string from a string
    ... I wrote a routine to strip any occurence of a character from a string (like ... Public Function oakStrip(StripString As String, ... Dim strChar As String ...
    (microsoft.public.vb.general.discussion)