﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24438	Django: Sqlite and regexp in query	Vera Mazhuga	nobody	"I'm using Django with a PostgreSQL database and this query works fine:

{{{#!python
    REQUEST_TYPE_ENTRANCE = 1
    REGEX_ENTRANCE = r'^{0},|,{0},|,{0}$|^{0}$'.format(
        REQUEST_TYPE_ENTRANCE
    )
    entrance_registers = EntranceRegister.objects.filter(authorized_requests__regex=REGEX_ENTRANCE)
}}}

But when I run tests with SQLite database it returns no results.

Here is the output of {{{print EntranceRegister.objects.filter(authorized_requests__regex=REGEX_ENTRANCE).query}}}:

{{{#!sql
    SELECT ""porter_entranceregister"".""id"", ""porter_entranceregister"".""status"", ""porter_entranceregister"".""authorized_requests"", ""porter_entranceregister"".""gone_at"", ""porter_entranceregister"".""created_at"" 
    FROM ""porter_entranceregister"" 
    WHERE ""porter_entranceregister"".""authorized_requests"" 
    REGEXP ^1,|,1,|,1$|^1$  ORDER BY ""porter_entranceregister"".""created_at"" 
    DESC
}}}

I suppose that the problem might be with missing quotes here: https://github.com/django/django/blob/master/django/db/backends/sqlite3/base.py#L129, but when I change this file in my virtualenv, it fails with

{{{
    ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 7 supplied.
}}}

And when I execute the SQL I get the following error:

{{{OperationalError: unrecognized token: ""^""}}}"	Uncategorized	closed	Uncategorized	1.6	Normal	worksforme	SQLite		Unreviewed	0	0	0	0	0	0
