Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda