Skip to content

SELECT index from trip_bill.bill JSON

Note: This query was made using ChatGPT, I'm not quite sure why and how it does what it does but it does work. Note 2: You have to use another simpler WHERE filter in conjuction with the JSON field WHERE filter, otherwise the query will take ages to finish and probably use quite a lot of computing power from the database.

SELECT 
    tb.index,
    tb.uuid
FROM 
    trip_bill tb
WHERE 
    EXISTS (
        SELECT 1 
        FROM jsonb_array_elements(tb.bill->'trip'->'route') AS route_elem
        WHERE org_uuid = '0a4f0f4b-24b6-448f-907e-38237bb87698' AND
        route_elem->>'booking_uuid' IN (
            '6628233b-bbb1-4440-afe2-7c766a05447e',
            '7c6f4d57-66c3-4bf0-97d9-88535365c211'
        )
    );