Hi all, is there any way using aggregation functio...
# orm-help
d
Hi all, is there any way using aggregation function on a computed value? for example:
Copy code
SELECT AVG(LENGTH(value)) FROM Word
Maybe something similar to
Copy code
prisma.word.aggregate({
    _avg: { value: { length: true } }
});
👀 1
r
Hi @Dor Meiri 👋 We could utilize the
QueryRaw
for this operation. For example:
Copy code
const result = await prisma.$queryRaw`SELECT  AVG(LENGTH(value)) FROM Word;
d
Hi @Raphael Etim, thanks for the answer, but this is something I want to generalize, I want to have the possibility having includes and where in the aggregation in various combinations. Doing it with
QueryRaw
can be bit messy. Is there an ORM-ish way of doing it?
r
I'm investigating this and will get back to you with a response.
👍 1
Hi @Dor Meiri,
QueryRaw
will be best in handling this but you can open a feature request so our team can look into implementing this.