question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

There’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:open
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vdboorcommented, Jul 29, 2019

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.

0reactions
vdboorcommented, Jul 29, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found