I have a table that has 2 columns, id (int auto_increment) and resp (json).
In this table I have duplicate values in the resp column, something like this:
id | resp -------------------------------------------- 1 | {"nome": "Jonh Doe", "idade": 20} 2 | {"nome": "Jonh Doe", "idade": 20} 3 | {"nome": "Maria Claire", "idade": 38} 4 | {"nome": "James Connor", "idade": 50}
I would just need to make a famous and traditional SELECT DISTINCT resp FROM tabela
, but because of the resp
column it is of type JSON , I can not do DISTINCT, PostgreSQL returns the following message:
ERROR: could not identify an equality operator for type json
I've already researched some solutions and tried the following, but they did not work:
Try 1:
SELECT
DISTINCT field
FROM (
SELECT jsonb_object_keys(resp) AS field
FROM public.tabela
) AS subquery
--------------
ERROR: function jsonb_object_keys(json) does not exist
Attempt 2:
SELECT
DISTINCT field
FROM (
SELECT jsonb_array_elements(resp) AS field
FROM public.tabela
) AS subquery
--------------
ERROR: function jsonb_array_elements(json) does not exist
Try 3:
SELECT
DISTINCT field
FROM (
SELECT json_array_elements(resp) AS field
FROM public.tabela
) AS subquery
--------------
ERROR: could not identify an equality operator for type json