﻿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
27179	Bug: error when trying to filter using regex/iregex on a key in a django.contrib.postgres.fields.JSONField	jrhouston		"When trying use regex to query on a key within a postgres JSONField.

{{{
TestModel.objects.filter(field__subkey__regex=r'test')
}}}

Generates SQL which produces the following error:

{{{
LINE 1: ...WHERE ""test_testmodel"".""field"" -> 'subkey'::text ~ 'test'
                                                                                                               ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
}}}

This seems to be a precedence issue, and adding parenthesis before the extracted key is cast to `::text` allows the query to run successfully. i.e:

{{{
WHERE (""test_testmodel"".""field"" -> 'subkey')::text ~ 'test'
}}}

Adding the parenthesis here seems to fix the issue: https://github.com/django/django/blob/master/django/contrib/postgres/fields/jsonb.py#L109"	Bug	closed	contrib.postgres	1.10	Normal	duplicate			Accepted	1	0	0	0	1	0
