Apparently, PostgreSQL 8.4 and Ubuntu 10.04 cannot handle the updated sorting method for W and V for the Swedish alphabet. That is, he still arranges them as the same letter (old definition for Swedish order):
it should be (new definition for Swedish order):
I need to do this correctly for the Python / Django site that I am creating. I tried various ways to simply organize the list of tuples created from QuerySet Django using * values_list *. But since the Swedish letters å, ä and ö must be properly ordered. Now I have either one or the other way and not both.
list_of_tuples = [(u'Wa', 1), (u'Vb',2), (u'Wc',3), (u'Vd',4), (u'Öa',5), (u'äa',6), (u'Åa',7)] print '########## Ordering One ##############' ordered_list_one = sorted(list_of_tuples, key=lambda t: tuple(t[0].lower())) for item in ordered_list_one: print item[0] print '########## Ordering Two ##############' locale.setlocale(locale.LC_ALL, "sv_SE.utf8") list_of_names = [u'Wa', u'Vb', u'Wc', u'Vd', u'Öa', u'äa', u'Åa'] ordered_list_two = sorted(list_of_names, cmp=locale.strcoll) for item in ordered_list_two: print item
Examples give:
Now what I want is their combination, so the correct V / W and å, ä, ö settings are correct. More precisely. I want Ordering One to comply with the locale. By then, using the second element (object id) in each tuple, I could get the correct object in Django.
I begin to doubt that this will be possible? Will there be a PostgreSQL update with a newer version that handles sorts better and then uses raw SQL in Django?