Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Sequelize operators conditional count

My question is how can I write a query for the conditional count. I have an array of objects like this on my Postgres table which is jsonb

"instances": [
    {
        "type": "bbox",
    },
    {
        "type": "bbox",
    },
    {
        "type": "bbox",
    },
    {
        "type": "ellipse"
    }
]

I have to find count of rows for which, for example, in the instances array there are more than two objects which type is equal to boxx, but with sequelize operators

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

sql solution

"I need to write some query like this to find rows with bbox or ellipse"

SELECT *
  FROM your_table AS t
 WHERE jsonb_path_exist(t.your_json_column :: jsonb, '$.**.keyvalue() ? (exists(@.key == 'bbox' || @.key == 'ellipse'))')

"I have to find count of rows for which, for example, in the instances array there are more than two objects which type is equal to bbox"

SELECT count(*)
  FROM your_table AS t
 CROSS JOIN LATERAL
     ( SELECT count(*) AS count
         FROM jsonb_path_query(t.your_json_column :: jsonb, '$[*] ? (@.type == "bbox")')
     ) AS c
 WHERE c.count > 2
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!