Using the SQL Having clause

What is the feature?

I would like to use the sql HAVING clause. Maybe I’m wrong but I think it’s not supported yet because when I’m looking at the aggregate I don’t see the way to do it

What problem does this solve for you?

I want to implement the replaceFieldOperator for a smart field that group and sum a column of childrens in a one to many relationship

Hi quentin

Hope you are doing well
Did you check this page?

You should be able to use a native SQL query and then build a condition tree targeting the pk.

Not the most efficient, but it should get the job done :slightly_smiling_face:

  const rows = await context.collection.nativeDriver.rawQuery(`
    SELECT id FROM x WHERE Y GROUP BY z HAVING q
  `);

  return { field: 'id', operator: 'In', value: rows.map(r => r['id']) };
});
1 Like