I am trying to check if the first 3 characters of Charfield (charfield_1) are similar to another Charfield (charfield_2) of the same model.
I tried:
User.objects.filter(charfield_2__startswith=Substr('charfield_1', 1, 3))
Tried to use F and Func without any success. I keep getting:
django.db.utils.DataError: invalid input syntax for integer: "1%" LINE 1: ...CE(REPLACE((SUBSTRING("model_name"."charfield_2", '1%', 3)),...
Any idea how to make this work? I would like the solution to use ORM to avoid performance issues.
Update:
After checking the query generated by ORM and the error message, it seems that the second Substr parameter is replaced with non-integer when I use startswith or contains a search expression.
ex: Substr ('charfield_1', 1, 3) is replaced by Substr ('charfield_1', '% 1%', 3)
I am using version 2.0.2.
A ticket was opened and accepted: https://code.djangoproject.com/ticket/29155
source share