-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBError: could not identify an equality operator for type json when annotating a model with JSONField #55
Comments
Oh, I might actually have created a duplicate in #57 . It seems to be linked to the use of |
I'm also running into this. Here's a more explicit example. models.py:
Here's the query that breaks, and the traceback:
Here's the query created for Postgres:
If you cast the JSON field in the GROUP BY clause to text, no exception is raised.
Not sure what the fix is, but hopefully that provides more information. |
I am getting the same error as above and it gets fixed too by casting the JSON field to text. |
Hopefully @mjtamlyn will fix this issue with his kickstarter project The issue seems to be that postgres does not provide a equality operator for json. I am not sure it is clear what equality should be for json. Is Maybe the json field can be cast to |
Checking whether two JSON blobs are equal is a non trivial exercise (to do it properly, it most likely involves sorting all keys in all nested objects and doing a text comparison. As a result, postgres does not implement an equality operator by design. Our options therefore are somewhat limited. A In short, JSON is a bad datatype in postgres to query on - it's very underpowered. It's designed for unstructured, additional metadata, not for critical querying data. In a reasonable number of cases, you're better off working with hstore than with json (which does have an equality operator). |
Yes, but then, one needs to tell django not to use this field for the kind of query that needs comparisons, and it's also not-trivial. Except if it is, but I don't think we have a simpler solution yet. |
Yup, that'll be my problem to solve |
Looking at the generated SQL this problem arises due to the JSON field being present in the ORDER BY clause when doing any sort of aggregation. PostgreSQL seems to not mind if you remove JSON types from the ORDER BY clause but leave them in the SELECT. |
Just pushed django-jsonfield 1.0.0 which makes the breaking change of dropping the native JSON data type from PostgreSQL. This should resolve the short-term errors, and in the long-term we can evaluate adding it back as better support emerges. |
I'm working in Django 1.5.4 with PostgreSQL 9.3, and i get this error on a query like this:
Traceback:
Ideas? I saw another issue with similar error, going to try and find out what causes this.
The text was updated successfully, but these errors were encountered: