Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Perform Group By with Date Extraction in Prisma #24156

Closed
Chandan-Kalita opened this issue May 11, 2024 · 0 comments
Closed

How to Perform Group By with Date Extraction in Prisma #24156

Chandan-Kalita opened this issue May 11, 2024 · 0 comments

Comments

@Chandan-Kalita
Copy link

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.

@prisma prisma locked and limited conversation to collaborators May 13, 2024
@janpio janpio converted this issue into discussion #24169 May 13, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant