#23423: Integrate unaccent lookups in django.contrib.postgres
-------------------------------------+-------------------------------------
     Reporter:  Thomas Chaumeny      |                    Owner:  Thomas
                                     |  Chaumeny
         Type:  New feature          |                   Status:  closed
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Gabor Körber):

 bilaterality of this function maybe should be explained in the
 documentation.

 also there is a caveat, and i want to comment it here, as this
 implementation caused me to debug for a while:

 if i do (please note how the sequence of enclosing is for unaccent and
 lower, also what follows are just abstract examples, i know there are
 possible workarounds!)

 {{{#!python
     Model.objects.annotate(a_value=Unaccent(Lower('fieldname'))).filter(
 a_value=Lower( 'another_field_or_Value' ) )
 }}}

 you would expect (abstractly) something like this SQL:

 SELECT * WHERE unaccent(lower(fieldname)) = lower(another_field_or_Value);

 however what you get is (because of bilateral "magic"):

 SELECT * WHERE unaccent(lower(fieldname)) =
 lower(unaccent(another_field_or_Value))

 less of a problem, as most likely you would want anyway something like

 {{{#!python
     Model.objects.annotate(a_value=Unaccent(Lower('fieldname'))).filter(
 a_value=Unaccent(Lower( 'another_field_or_Value' )) )
 }}}

 however this expression results in django as

 SELECT * WHERE unaccent(lower(fieldname)) =
 unaccent(lower(unaccent(another_field_or_Value)))

 this would not make much issues, you can just leave out unaccent on RHS as
 you will get it from annotate, especially if lower and unaccent were
 interchangable in their position
 but they are not, there are exceptions

 see in postgres:

 select lower(unaccent('ÇÁÈÎËßÖÜ')), unaccent(lower('ÇÁÈÎËßÖÜ'));

 results in "caeiesou", "caeieSou"
 and these are just the european exceptions i checked, but be warned.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23423#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.cab0dac0a26cf1a25459a632c5aab249%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to