Skip to content
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

GroupBy WEEK, MONTH and YEAR doesn't work for postgres. #163

Closed
phamhunker opened this issue Aug 7, 2023 · 2 comments
Closed

GroupBy WEEK, MONTH and YEAR doesn't work for postgres. #163

phamhunker opened this issue Aug 7, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@phamhunker
Copy link

Is your feature request related to a problem? Please describe.
Currently grouping by week, month or year only works for MySQL, could we also get this to work for postgres as well?

Have you read the Contributing Guidelines?

No

Describe the solution you'd like
It'd be nice if group by time periods also worked for postgres as well.

Describe alternatives you've considered
None. Looks like I'll need to create a resolver.

Additional context

                if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.YEAR) {
                    query = `DATE(DATE_FORMAT(${col}, '%Y-01-01'))`;
                }
                else if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.MONTH) {
                    query = `DATE(DATE_FORMAT(${col}, '%Y-%m-01'))`;
                }
                else if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.WEEK) {
                    query = `STR_TO_DATE(DATE_FORMAT(${col}, '%X-%V-01'), '%X-%V-%w')`;
                }

Currently that's what the code looks like today, all functions afaik, are MySQL specific.

@phamhunker phamhunker added the enhancement New feature or request label Aug 7, 2023
@TriPSs
Copy link
Owner

TriPSs commented Aug 8, 2023

Thanks for posting, I created a PR (#165) that contains a test case for this (which fails now on postgres) will try to check this out when I have some time.

@TriPSs TriPSs closed this as completed in 7e60f09 Oct 31, 2023
@phamhunker
Copy link
Author

Awesome! thanks for the work :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants