#29155: Using contains field lookup with Substr database function cause
modification of second parameter of Substr
-------------------------------------+-------------------------------------
               Reporter:  norac89    |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 My model:


 {{{
 class User(models.Model):
     field1 = models.Charfield(max_length=120)
     field2 = models.Charfield(max_length=120)
 }}}

 Tried querying the model to get User instances in which field2 start with
 the three first characters of field1.
 Tried the following:

 {{{
 User.objects.filter(field2__startswith=Substr(F('field1'), 1, 3))
 }}}

 I m getting the following error

 {{{
 psycopg2.DataError: invalid input syntax for integer: "1%"
 LINE 1: ...(REPLACE(REPLACE((SUBSTRING("test_user"."field1", '1%', 3)),...
 }}}

 The second parameter of the substr function seems to be replaced with
 '1%'.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29155>
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/050.4e6aba39405b6e63587c6bff258327b8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to