Views aggregation functions SUM, AVERAGE and STDDEV_POP causes "Undefined function error" when are used in some fields in postgresql

Created on 4 December 2018, almost 6 years ago
Updated 4 May 2023, over 1 year ago

Problem/Motivation

1) Install last Drupal 8 version (8.6.2 at the moment) with postgresql (9.6.10)
2) Create a custom numeric field for a content type (for example field_points in Article)
3) Create a couple of articles and fill with a number your custom field points.
3) Create a view with filter content type = "Article" , Format = "Table" , and with fields "Title" and "Points".
4) Set Advanced > Use aggregation:Yes
5) In aggregation settings of points field set "Aggregation type" = SUM and "Group column" = VALUE

View has no results and show this error:

"SQLSTATE[42883]: Undefined function: 7 ERROR: function sum(character varying) does not exist LINE 1: ..._field_points.delta) AS node__field_points_delta, SUM(node__... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.: SELECT node_field_data.title AS node_field_data_title, SUM(node__field_points.field_points_value) AS node__field_points_field_points_value, SUM(node__field_points.delta) AS node__field_points_delta, SUM(node__field_points.langcode) AS node__field_points_langcode, SUM(node__field_points.bundle) AS node__field_points_bundle, MIN(node_field_data.nid) AS nid FROM {node_field_data} node_field_data LEFT JOIN {node__field_points} node__field_points ON node_field_data.nid = node__field_points.entity_id AND node__field_points.deleted = :views_join_condition_0 AND (node__field_points.langcode = node_field_data.langcode OR node__field_points.bundle = :views_join_condition_2) WHERE (node_field_data.status = :db_condition_placeholder_3) AND (node_field_data.type IN (:db_condition_placeholder_4)) GROUP BY node_field_data_title; Array ( [:db_condition_placeholder_3] => 1 [:db_condition_placeholder_4] => article [:views_join_condition_0] => 0 [:views_join_condition_2] => position )

This error doesn't happen with other no-custom fields like node ID or creation date, etc ... and doesn't happen with other functions like MIN and MAX.

πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
ViewsΒ  β†’

Last updated about 8 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain qpro Spain

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024