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
[BUG] Opensearch returns null for all columns not listed in GROUP BY statement #258
Dear @chloe-zh,
Sorry for providing a mislead example. Even if column specified in GROUP BY statement added to the result set, other columns have only nulls:
opensearchsql> select `key` as KK, int1, bool0 from calcs GROUP BY bool0;
fetched rows / total rows = 3/3
+------+--------+---------+
| KK | int1 | bool0 |
|------+--------+---------|
| null | null | null |
| null | null | False |
| null | null | True |
+------+--------+---------+
Actually, different SQL servers (and different versions) have different behavior. Usually, server reject query if it has a column without an aggregation function and not listed in GROUP BY. Some servers/versions produce multi-line output (like GROUP BY replaced by ORDER BY) or apply default aggregation function (e.g. CONCAT).
It should be discussed and defined what result should returned in such case. Returning nulls is also an option, but it must be proven/confirmed as a best one or most suitable one.
mysql> select `key` as `KK`, `int1`, `bool0` from calcs GROUP BY `bool0`;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'TDVT.calcs.key' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Activity
chloe-zh commentedon Nov 2, 2021
Hi @Yury-Fridlyand i think it's probably because the group by item was not present in the select items, could you try the following query:
Yury-Fridlyand commentedon Nov 4, 2021
Dear @chloe-zh,
Sorry for providing a mislead example. Even if column specified in
GROUP BYstatement added to the result set, other columns have only nulls:Actually, different SQL servers (and different versions) have different behavior. Usually, server reject query if it has a column without an aggregation function and not listed in
GROUP BY. Some servers/versions produce multi-line output (likeGROUP BYreplaced byORDER BY) or apply default aggregation function (e.g.CONCAT).It should be discussed and defined what result should returned in such case. Returning
nulls is also an option, but it must be proven/confirmed as a best one or most suitable one.Yury-Fridlyand commentedon Nov 4, 2021
If aggregation function is specified, OpenSearch returns a valid result:
Yury-Fridlyand commentedon Nov 2, 2022