How to Perform Group By with Date Extraction in Prisma #24169
Unanswered
Chandan-Kalita
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi @Chandan-Kalita 👋 Thank you for raising this question. At the moment, using raw queries will be the way to implement this as we do not support |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
Performing a group by operation in Prisma that involves date extraction from a timestamp column ("createdAt") in PostgreSQL is currently challenging. The goal is to sum a specific column ("totalFare") grouped by the month extracted from the "createdAt" timestamp.
Suggested solution
I would like to be able to write a query in Prisma that performs a group by operation based on the month extracted from a timestamp column ("createdAt") and then calculates the sum of a specific column ("totalFare") for each month.
Alternatives
To achieve the desired functionality, a workaround involves using a raw SQL query alongside Prisma's capabilities. This allows incorporating the EXTRACT function for date extraction within the GROUP BY clause.
Additional context
Currently, Prisma's groupBy method does not directly support the EXTRACT function for date extraction within the groupBy clause. Utilizing raw SQL queries introduces the risk of SQL injection, so caution must be exercised when implementing this approach. The ability to handle date extraction within Prisma's groupBy method would streamline query operations and enhance compatibility with PostgreSQL-specific functionalities.
Beta Was this translation helpful? Give feedback.
All reactions