On Tue, Jun 8, 2010 at 2:34 PM, steven314 <stevenredtrous...@gmail.com> wrote:
> Thanks Dimitry,
>
>> If you want space to take part in comparison, use char fields instead of
>> varchar. See:http://dev.mysql.com/doc/refman/5.0/en/char.html
>
> The below quote from the reference link you sent would seem to
> indicate that trailing spaces *do not* take part in the comparison in
> char fields either?
> "All MySQL collations are of type PADSPACE. This means that all CHAR
> and VARCHAR values in MySQL are compared without regard to any
> trailing spaces."
>
> Regardless, one would surely not wish to force a specific storage type
> from within Django.
>
> Steven.
>

This is something that the mysql backend _could_ take care of,
particularly when doing a 'foo__exact' lookup. MySQL will ensure that
the string exactly matches the database when you use the construct
'WHERE BINARY <field> = <value>'

Eg:

mysql> create temporary table foo ( msg varchar(32) );
Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo values ('hello '), ('hello    '), ('hello');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from foo where msg ='hello';
+-----------+
| msg       |
+-----------+
| hello     |
| hello     |
| hello     |
+-----------+
3 rows in set (0.00 sec)

mysql> select * from foo where binary msg ='hello';
+-------+
| msg   |
+-------+
| hello |
+-------+
1 row in set (0.00 sec)

This may have other unintended side effects, certainly it will make
the match case sensitive, I'm not sure if __exact is supposed to be
case sensitive.

Alternatively, the column type for varchar columns could be changed to
binary VARCHAR, which has the same effect and doesn't require
alterations to any queries.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to