I was reading a query that had the all
keyword within a function call:
select count(all 97);
┌───────────┐
│ count(97) │
╞═══════════╡
│ 1 │
└───────────┘
Elapsed: 11 ms
What does all
(outside a subselect) do in postgres? I was having a hard time finding it in the documentation.
2
Answers
Seems it's just an explicit way to say 'default behavior' as opposed to doing
COUNT(DISTINCT ...)
. From the docs:https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-AGGREGATES
ALL
is a "set quantifier" as well asDISTINCT
for aggregated functions. It’s defined in section 6.5 of the SQL Standard SQL-92.It means that all values need to be considered — as in a multiset — and not only distinct values — as in a set. It’s the default behavior if no quantifier is specified.
Excerpt from SQL-92: