On 2 February 2012 03:34, Anssi Kääriäinen <anssi.kaariai...@thl.fi> wrote:
>
> Now, my proposed solution would be to have some way of doing:
> SELECT name, ...
> FROM authors
> ORDER BY name collate 'fi';
>
> That some way might be something like
> .order_by('name', collate='fi')
> or maybe
> .collate('fi').order_by('name')
> and now collate would be in effect for filters (that is,
> name__gte='e'), too.
>

The user should probably be able to specifiy the collation only for
the fields he wants, as it most likely uses a different type of index
and is more expensive then a standard ordering, so I like the
.collate(name="fi") option (and a shortcut of .collate("fi") to apply
to all text fields.

>
> Making Django's ORM do the above isn't the most trivial thing. And not
> all databases support collate clauses.

After a quick research, I think they actually do now (at least in
ORDER BY). MySQL[1] and SQLite[2] both have COLLATE, in Oracle we
could use NLSSORT()[3] which is something like locale.strxfrm.

>
> You can do the above with .extra() even now if your DB happens to
> support collations. Default collation for your database might also be
> an option for your particular problem. At least in PostgreSQL versions
> prior to 9.1 you have one collation for the DB, which you can set only
> at CREATE DB time.
>

[1]: At least since 5.0:
http://dev.mysql.com/doc/refman/5.0/en/charset-collate.html
[2]: SQLite doesn't support UCA by default, but lets you define any
collation: 
http://docs.python.org/library/sqlite3.html#sqlite3.Connection.create_collation
[3]: http://docs.oracle.com/cd/B19306_01/server.102/b14225/ch9sql.htm#i1006311

-- 
Łukasz Rekucki

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

Reply via email to