-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix(model): count() code generation for distinct rows #11893
Conversation
Add code to count() to cause it to create valid SQL when distinct=true and col is unspecified or "*". Otherwise the SQL generated is COUNT(DISTINCT(*)), which is invalid. Issues referenced below were already closed, but the issue hadn't actually been fixed, and it _keeps coming up_. Closes: sequelize#2713, sequelize#6404, sequelize#6418, sequelize#7344
Looking at the failed build, the failure is unrelated to my PR. |
Bump. Any chance we can get this merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but will need a PR to master before we can merge this to v5
@sushantdhiman #11946 submitted as a PR to master. |
🎉 This PR is included in version 5.21.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Pull Request check-list
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Add code to
count()
to cause it to create valid SQL whendistinct=true
andcol
is unspecified or"*"
. Otherwise the SQL generated isCOUNT(DISTINCT(*))
, which is invalid. Issues referenced below were already closed, but the issue hadn't actually been fixed, and it keeps coming up.Made this change against v5, because I need it ASAP, but the identical change should work against v6. I can submit another PR against
master
Notes:
Tested against Postgres 11 only. Three time-based tests failed; it seems like there's a time zone issue? Some other Model/create test failed, also likely due to database version mismatch (permission denied to create extension "uuid-ossp"). Sorry, I don't have time to install the custom Docker Postgres; the related tests passed.
Related tickets: #2713, #6404, #6418, #7344 -- all were "closed", but none were previously actually fixed. Workarounds were listed, but those workarounds don't work at all if you're using Sequelize with Feathers-Sequelize and Sequelize-TypeScript. Besides, Sequelize shouldn't generate bad code when the options aren't perfect.