findAndCountAll does not work with distinct, count is right but rows is wrong
See original GitHub issueIssue 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: sequelize@5.19.0
- 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:15 (1 by maintainers)
Top Results From Across the Web
How to get a distinct count with sequelize? - Stack Overflow
count method in lib/model.js, and tracing some code, I found that when using Model.count , you can just add any kind of aggregate...
Read more >Aggregation, grouping, and summarizing (Concepts) - Prisma
Aggregation, grouping, and summarizing. Prisma Client allows you to count records, aggregate number fields, and select distinct field values.
Read more >COUNT function - Amazon Redshift
The COUNT function counts the rows defined by the expression. ... For smaller sets of distinct values, in the thousands, approximation might be...
Read more >Model Querying - Basics - Sequelize
Transactions are important to ensure data integrity and to provide ... model to set only an username but not an admin flag (i.e.,...
Read more >Sequelize - how to COUNT table rows number with code ...
Sequelize Model.count() method is used to generate and execute a SELECT COUNT SQL query to your connected database.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Bump
Still an issue. Version 5.21.5