I have a varchar column
{" l l": 2, " m m": 2, " xs xs": 2, " xxs xxs": 2, "s s": 0, "xl xl": 0}
How do I filter it to get only keys with values greater then 0?
Expected output is
{" l l": 2, " m m": 2, " xs xs": 2, " xxs xxs": 2}
I have a varchar column
{" l l": 2, " m m": 2, " xs xs": 2, " xxs xxs": 2, "s s": 0, "xl xl": 0}
How do I filter it to get only keys with values greater then 0?
Expected output is
{" l l": 2, " m m": 2, " xs xs": 2, " xxs xxs": 2}
2
Answers
One option to carry out this task is by:
JSONB_EACH_TEXT
to convert your json to tableJSON_OBJECT
+ARRAY_AGG
Output:
Check the demo here.
Your data looks like json so you can try to process it like one – parse as json, turn it into
map(varchar, integer)
(ordouble
), filter, turn back into string:Output: