Repository navigation
Open
Labels
topic: countFor issues and PRs. Things that involve counting such as the `count` and the `findAndCountAll` meth.type: bugDEPRECATED: replace with the "bug" issue type
Description
Issue Description
What are you doing?
// model
class Delta extends Sequelize.Model {}
Delta.init({
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
padId: Sequelize.STRING,
authorId: Sequelize.STRING,
// delta: Sequelize.JSONB,
delta: Sequelize.STRING(10000),
deltaId: Sequelize.INTEGER
}, { sequelize, modelName: 'delta' })
// query
let perPage = 25
let offset = 0
const result = await Delta.findAndCountAll({
limit: perPage,
offset,
order: [
['padId', 'ASC']
],
distinct: true,
col: 'delta.padId'
})What do you expect to happen?
It should count the distinct padIds and result.rows should be an array containing all the padId's
What is actually happening?
The count is working, the select just selects all the parameters instead of just the distinct padIds
Executing (default): SELECT count(DISTINCT("delta"."padId")) AS "count" FROM "delta" AS "delta";
Executing (default): SELECT "id", "padId", "authorId", "delta", "deltaId", "createdAt", "updatedAt" FROM "delta" AS "delta" ORDER BY "delta"."padId" ASC LIMIT 25 OFFSET 0;
Additional context
Add any other context or screenshots about the feature request here.
Environment
- Sequelize version: [email protected]
- Node.js version: v10.16.3
- Operating System: Ubuntu 19.04 amd64
- If TypeScript related: TypeScript version: none
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Reacted by BartusZak, qiuzi | 秋子, Adrián Mouly, Andrey Kostiv and Pat McCauley
Metadata
Metadata
Assignees
Labels
topic: countFor issues and PRs. Things that involve counting such as the `count` and the `findAndCountAll` meth.type: bugDEPRECATED: replace with the "bug" issue type
Type
Projects
- StatusShow more project fieldsNo status
Activity
EricPKerr commentedon Sep 25, 2019
I think I have a fix for this, but I'm not quite sure how to pull it into this project:
In
abstract/query-generator.jsChange:
To this:
Basically you don't want the LIMIT/OFFSET part to be in the subQuery if there are any joined (included) tables that are
required: trueand would potentially restrict the results. You need to move these to themainQueryItemsouter query.Only thing I'm not sure about is what
hasParentRequiredmeans in theoptions, and if this should actually be:BartusZak commentedon Dec 2, 2019
Any update on that?
SuperManifolds commentedon Dec 20, 2019
Bump
papb commentedon Jan 16, 2020
Related: #9481, #10137 and #10557,
RomeDorado commentedon Mar 30, 2020
Still an issue.
Version 5.21.5
yongching commentedon Jun 13, 2020
Bump
vndevil commentedon Jun 16, 2020
Bump
hiitsgabe commentedon Aug 13, 2020
Bump
ori-osherov-vonage commentedon Nov 17, 2020
Bump
hiitsgabe commentedon Nov 24, 2020
I am using
attributes: [[Sequelize.fn('DISTINCT', Sequelize.col('user_email')), 'user_email']] as a workaround to the problem. Works for me.
mihai10001 commentedon Mar 5, 2021
Bump
Adam-Burke commentedon Apr 8, 2021
help
PokatilovArt commentedon Jun 21, 2021
#2713 (comment)
worked for me
O-mkar commentedon Nov 2, 2021
Same for me, Help
Still an issue.
Version 6.6.2
dormeiri commentedon Mar 16, 2022
This what worked for me:
Seems like
attributesproperty is for the SELECT and thecol/distinctproperties are for the COUNT