Problem/Motivation
Adding only a field with a COUNT aggregation on nid, adds a second nid without a GROUP BY clause resulting in this
SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'db.node_field_data.nid'; this is incompatible with sql_mode=only_full_group_by: SELECT "node_field_data"."nid" AS "nid_1", COUNT(node_field_data.nid) AS "nid" FROM "node_field_data""node_field_data" WHERE ("node_field_data"."status" = :db_condition_placeholder_0) AND ("node_field_data"."type" IN (:db_condition_placeholder_1)); Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => course_section )
This is a regression from D7 views as this would produce the COUNT only field.
Steps to reproduce
- Create a new node view on article bundle
- Remove sort clause that gets added and title field
- Turn on aggregation
- Add COUNT on nid field
Proposed resolution
Avoid adding the nid via getEntityTableInfo() when it's not needed, or add the appropriate GROUP By to the field it adds
@see
\Drupal\views\Plugin\views\query\entity_information
core/modules/views/src/Plugin/views/query/Sql.php:1344