PostgreSQL jsonb count where keys have a certain value

  Kiến thức lập trình

How can I get filter the rows where the number of keys in a jsonb column object have a specific value? I’ve got a jsonb column that contains something like

{
  "fri": "from_home",
  "mon": "from_home",
  "sat": "dont_work",
  "sun": "dont_work",
  "thu": "commute",
  "tue": "from_home",
  "wed": "commute"
}

What I want to do is get all the rows where this column has say 3 days set to “from_home”. I’ve been looking through the various pg functions for JSON but I’m just getting lost as to what would be the best fit.

LEAVE A COMMENT