You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is distinct option for Model.count() actually working? #4840
I have a Postgres database. In latest docs, distinct is listed under options that can be passed to Model.count() function. However, as col is explicitely set to '*' in this function implementation, resulting query looks as follows SELECT COUNT(DISTINCT(*)) ...
which doesn't seem to be a valid query:
Executing (default): SELECT count(DISTINCT(*)) AS "count" FROM "Comments" AS "Comment";
Wed Nov 11 2015 21:23:23 GMT+0100 (CET) 'SequelizeDatabaseError' 'syntax error at or near "*"'
'SequelizeDatabaseError: syntax error at or near "*"
at Query.formatError (/node_modules/sequelize/lib/dialects/postgres/query.js:443:14)
at null.<anonymous> (/node_modules/sequelize/lib/dialects/postgres/query.js:118:19)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at Query.handleError (/node_modules/pg/lib/query.js:108:8)
at null.<anonymous> (/node_modules/pg/lib/client.js:171:26)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at Socket.<anonymous> (/node_modules/pg/lib/connection.js:109:12)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)'
I tried also passing where or attributes hoping that this will change the resulting column, but the result is still the same. So, what is the proper way to use this option?
Activity
mickhansen commentedon Nov 12, 2015
It's most likely not working looking at the code. The option description was likely copied from the aggregate method which count relies on.
JakubJagoda commentedon Nov 12, 2015
Does it mean the bug is in the implementation or rather in the documentation (and shouldn't be there)?
janmeier commentedon Nov 18, 2015
Its used in connection with includes, where the field default to
idsequelize/test/integration/model.test.js
Line 1783 in 8059256
Perhaps count should allow the user to set
.col, that would make the distinct option useful