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

Alias And Field Names In Generated SQL For Aggregate GroupBy Date Are Not Properly Escaped With Quotes #238

Open
dvins opened this issue Mar 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dvins
Copy link

dvins commented Mar 24, 2024

Describe the bug
When using groupBy date the alias and field names in the generated SQL are not being properly escaped, resulting in an invalid query and failure.

Have you read the Contributing Guidelines?

Yes.

To Reproduce
Steps to reproduce the behavior:

  1. With a backing Postgres data structure wherein the schema concerns a TypeORM ViewEntity class named UserRecord targeting the database schema tenant and view user.
  2. Issue an aggregate query, such as:
{
  userAggregate {
    groupBy {
      createdAt(by: MONTH )
    }
    count {
      userId
    }
  }
}

After which an error is thrown by the database and introspection of the generated SQL for the query shows that the alias and field name in the TO_CHAR() function for the group by aggregate is not properly escaped in quotes, whereas the count aggregate is.

SELECT
  DATE(TO_CHAR(UserRecord.createdAt, 'YYYY-mm-01')) AS "GROUP_BY_createdAt",
  COUNT("UserRecord"."userId") AS "COUNT_userId"
FROM
  "tenant"."user" "UserRecord"
GROUP BY
  "GROUP_BY_createdAt"
ORDER BY
  "GROUP_BY_createdAt" ASC

Expected behavior
The generated SQL does not error and results are subsequently returned.

Desktop (please complete the following information):

  • Node Version: v20.6.0
  • Nestjs-query Version: v4.3.3
@dvins dvins added the bug Something isn't working label Mar 24, 2024
@TriPSs
Copy link
Owner

TriPSs commented Mar 25, 2024

Interesting, we do not do anything special or more for the COUNT. What driver are you using as the tests for MySQL and Postgres both pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants