Assuming we have a table where column data stores an array of objects.
┌────┬───────────────────────────────────────────────────────────────────────┐
│ id │ data │
├────┼───────────────────────────────────────────────────────────────────────┤
│ 1 │ [{"m2": 40.0, "sector": "Office"}, {"m2": 65.0, "room": "Hospital"}] │
│ 2 │ [{"m2": 25.0, "sector": "Cafe"}, {"m2": 120.0, "room": "Office"}] │
│ 3 │ [] │
└────┴───────────────────────────────────────────────────────────────────────┘
I would like to find only these objects, which have the m2 value the highest.
┌────┬─────────────────────────────────────────┐
│ id │ data │
├────┼─────────────────────────────────────────┤
│ 1 │ {"m2": 65.0, "room": "Hospital"} │
│ 2 │ {"m2": 120.0, "room": "Office"} │
│ 3 │ null │
└────┴─────────────────────────────────────────┘
PostgreSQL 13.4