我使用Django與PostgreSQL數據庫的正則表達式和這個查詢工作正常:Django的:SQLite和查詢
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)
但是,當我運行SQLite數據庫測試中,它不返回任何結果。
這裏是print EntranceRegister.objects.filter(authorized_requests__regex=REGEX_ENTRANCE).query
輸出:
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
我想,這個問題可能是在這裏失蹤報價:https://github.com/django/django/blob/master/django/db/backends/sqlite3/base.py#L129,但是當我在我的virtualenv修改了這個文件,它失敗
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 7 supplied.
它的工作原理'? – FeedTheWeb 2015-03-02 15:34:58
@lxer它返回:''OperationalError:無法識別的令牌:「^」'' – vero4ka 2015-03-02 15:44:13