Filtering not working with postgreSQL: " No operator matches the given name and argument type(s). You might need to add explicit type casts."
See original GitHub issueThere’s a “bug” in postgreSQL (in fact, it’s more a feature: strong typed, contrary to MySQL which is “weakly typed”, since PostgreSQL 8.3):
Now if you’ve got: models.py
class ArticlesTable(models.Model):
id = models.IntegerField(primary_key=True)
comments_set = CommentsRelation()
...
and if you want to display the Articles, for which there’s comment, for example, you do:
views.py
latest_comments = ArticlesTable.objects.filter(comments_set__isnull=False)
But PostgreSQL doesn’t like that! error:
ProgrammingError at /
operator does not exist: integer = text
LINE 1: ...ango_comments" ON ( "articles_articlesTable"."id" = "django_...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
How can we avoid this error when using simple filtering? Hint here: http://stackoverflow.com/questions/16044754/heroku-postgresql-django-comments-tastypie-no-operator-matches-the-given-na
But I don’t now how to change that…
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
No operator matches the given name and argument type(s ...
I had this issue, and solved. This was due to the WHERE clause contains String value instead of integer value.
Read more >hint: no operator matches the given name and argument types ...
HINT: No operator matches the given name and argument types. You might need to add explicit type casts. postgres=# select * from test...
Read more >No operator matches the given name and argument type(s ...
Filtering over generic relations with TextField/CharField object_id gives PostgreSQL error: No operator ... You might need to add explicit type casts.
Read more >[PostgreSQL] No operator matches the given name and ...
[PostgreSQL] No operator matches the given name and argument type(s). You might need to add explicit type casts. Problem I have a table ......
Read more >[Django] #20271: PostgreSQL error: No operator matches the ...
#20271: PostgreSQL error: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks! I see now what’s happening. This is because Django’s “GenericForeignKey” uses a Text field for the ID field. In postgres, this breaks with fields that store the data in a UUIDField.
This is clearly an issue for https://github.com/django/django-contrib-comments, as they’ve implemented the base model that we build upon.
Ah that’s indeed how it should be implemented. This is one for https://github.com/django/django-contrib-comments though, as we mainly provide nice Ajax UI fluff on top of it!