Hi, I want to filter a set of records where a spec...
# sql
d
Hi, I want to filter a set of records where a specific column is an array of JSON. The following query:
Copy code
SELECT 
  s.*,
  p
FROM service s
CROSS JOIN LATERAL json_array_elements(pets) p
WHERE p->>'type' == 'dog'
returns an error:
Copy code
function json_array_elements(json[]) does not exist
Any idea? The column is a json[] datatype and the data instead is
Copy code
[
  {
    "type": "cat",
    "price": 10
  },
  {
    "type": "dog",
    "price": 20
  }
]
I've read the official documentation about JSON data https://supabase.io/docs/guides/database/json - but there is no mention of an array of objects.
t
I’m thinking you may be able to unnest pets before:
json_array_elements(unnest(pets))