Menu

Extra spaces in returned varchar field values

Help
WvV
2007-10-02
2012-09-19
  • WvV

    WvV - 2007-10-02

    Since we switched to a new server with a new version of MySql (v5.0), the select queries on varchar fields return, with the value filled out with spaces to the length of the varchar field. This broke some of my pythonscripts because that was unexpected. It was easily fixed by an .rstrip() on the field before usage... But I'm wondering what causes this?

    • Is this a feature? ;)
    • Am I missing an option, that turns this behaviour on by default?
    • Is this a bug in MySQL for Python?
     
    • WvV

      WvV - 2007-10-15

      You put me on the right track. I could trace the problem to a dbf to mysql conversion program that inserts the values complete with trailing spaces. Which was no problem with the older mysql (because they where stripped as you pointed out), but after the upgrade this became evident...
      Thank you!

       
    • Kyle VanderBeek

      Kyle VanderBeek - 2007-10-13

      It might be you. Old MySQL (before 5.0.3) stripped trailing space from varchars, which was dumb. Maybe you're inserting values with trailing spaces, and new MySQL is (correctly) returning the exact value you stored.

      From http://dev.mysql.com/doc/refman/5.0/en/char.html

      "VARCHAR values are not padded when they are stored. Handling of trailing spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL. Before MySQL 5.0.3, trailing spaces are removed from values when they are stored into a VARCHAR column; this means that the spaces also are absent from retrieved values."

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.