Issue: PostgresqlExtDatabase. Model with JSONField raise exception on any action with search (get, get_or_create, etc.)
Author: olvinroght
State: closed
Created: 2021-12-17 10:50:01

```python
from playhouse.postgres_ext import PostgresqlExtDatabase, JSONField
from peewee import Model, CharField

database = PostgresqlExtDatabase("Test", user="user", password="password", 
                                 host="localhost", port=5432, autorollback=True)

class TestJSONModel(Model):
    name = CharField(unique=True)
    json_value = JSONField()

    class Meta:
        database = database

TestJSONModel.create_table()
model, created = TestJSONModel.get_or_create(
    name="test_json_model_1",
    json_value={"key1": "value1"}
)
```
It raises an exception:
```none
Traceback (most recent call last):
  File "\venv\lib\site-packages\peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.errors.UndefinedFunction: ERROR: operator does not exist: json = json
LINE 1: ..."name" = 'test_json_model_1'), ("t1"."json_value" = CAST('{"...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "\test.py", line 24, in <module>
    model, created = TestJSONModel.select(
  File "\venv\lib\site-packages\peewee.py", line 1911, in inner
    return method(self, database, *args, **kwargs)
  File "\venv\lib\site-packages\peewee.py", line 1982, in execute
    return self._execute(database)
  File "\venv\lib\site-packages\peewee.py", line 2155, in _execute
    cursor = database.execute(self)
  File "\venv\lib\site-packages\playhouse\postgres_ext.py", line 490, in execute
    cursor = self.execute_sql(sql, params, commit=commit)
  File "\venv\lib\site-packages\peewee.py", line 3167, in execute_sql
    self.commit()
  File "\venv\lib\site-packages\peewee.py", line 2933, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "\venv\lib\site-packages\peewee.py", line 191, in reraise
    raise value.with_traceback(tb)
  File "\venv\lib\site-packages\peewee.py", line 3160, in execute_sql
    cursor.execute(sql, params or ())
peewee.ProgrammingError: ERROR: operator does not exist: json = json
LINE 1: ..."name" = 'test_json_model_1'), ("t1"."json_value" = CAST('{"...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
```
Same happens on any other query where `json_value` comparison used. Code above produces next query:
```sql
SELECT ("t1"."name" = %s), ("t1"."json_value" = CAST(%s AS json)) FROM "testjsonmodel" AS "t1"
```
As far as I understood, it's not possible to compare JSON fields, only their string values, so it will be good if peewee handles it internally instead of raising an exception.

This happens only with `JSONField`, `BinaryJSONField` works well. There's [a question](https://stackoverflow.com/q/32843213/10824407) on Stack Overflow with same issue.


Refer to the docs: https://www.postgresql.org/docs/current/datatype-json.html

But, simply, you cannot compare `json` values. I am not aware of any reason why you would want to use `json` over `jsonb`, so I would suggest that you just use `BinaryJSONField` (which additionally supports indexing).

If you really want to use `JSONField` then you should not use `get_or_create()` but instead use `insert(...).on_conflict()` and rely on a unique constraint.