Opened 12 years ago
Last modified 12 years ago
#4354 closed defect
[PATCH] OGR SQL 'COUNT([DISTINCT] xx)' not conformant with other SQL implementations w.r.t NULL values — at Initial Version
Reported by: | Even Rouault | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 1.9.0 |
Component: | OGR_SF | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: |
Description
Currently, OGR SQL considers COUNT(a_column) as a synonym of COUNT(*). However the standard mandates that COUNT(a_column) only count non-NULL values, whereas COUNT(*) count all values, including NULL ones. So COUNT(a_column) should not be considered as equivalent to COUNT(*)
The same applies for COUNT(DISTINCT a_column): it should only count unique non-NULL values.
References :
- http://www.w3schools.com/sql/sql_func_count.asp
- http://msdn.microsoft.com/en-us/library/ms175997.aspx
- http://www.sqlite.org/lang_aggfunc.html
What is a bit annoying here is that ogr_sql.html says that : "As a special case, the COUNT() operator can be given a "*" argument instead of a field name which is a short form for count all the records though it would get the same result as giving it any of the column names [...]"
If we fix the current behaviour to be conformant with the standard, it can break assumptions made by users.