fix(model): count() code generation for distinct rows #11946
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add code to count() to cause it to create valid SQL when distinct=true and col 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.Closes: #11894, #2713, #6404, #6418, #7344
Pull Request check-list
npm run test
ornpm run test-DIALECT
pass with this change (including linting)? See BelowDescription of change
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.
#11893 was this PR against v5. This PR is against master.
Notes:
Tests: Tested against Postgres 11 only. There are failures, but they seem to be failures in
master
, not in anything that I changed. The only change I made is in thecount()
function, and none of the failures hits that function. 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.