Query to Find and Remove PG Duplicated JSONB Keys and Values

67 Views Asked by At

I would like to be able to Update JSONB column values by removing duplicates, and similarities.

JSONB VALUES:


    {"Service Types": {"INSURANCE": true, "Insurance": true}}
    {"Service Types": {"HOSPITALS": true, "Hospitals": true}}
    {"Service Types": {"DENTISTS": true, "Dentists": true}}
    {"Service Types": {"Physicians": true, "PHYSICIANS & SURGEONS": true}}
    

EXPECTED RESULT:


    {"Service Types": {"Insurance": true}}
    {"Service Types": {"Hospitals": true}}
    {"Service Types": {"Dentists": true}}
    {"Service Types": {"PHYSICIANS & SURGEONS": true}}
    

EXAMPLE OF DUPLICATES

Duplicates: {"INSURANCE": true, "Insurance": true} 
EXPECTED: {"Insurance": true} 

SIMILARITIES:

{"Physicians": true, "PHYSICIANS & SURGEONS": true} 
EXPECTED: {"Physicians": true,} or {"PHYSICIANS & SURGEONS": true} 
0

There are 0 best solutions below