Views should not use constant values or expressions in aggregates

Created on 14 November 2014, over 10 years ago
Updated 15 July 2025, 18 days ago

Problem/Motivation

Follow up from #2159347: Aggregation not working simple test case

Views is generating under some circumstances queries that have constant expressions inside the aggregation clause.

This, besides making no sense as constant values have no effect on aggregates, makes these queries incompatible with SQL Server and Oracle (probably Postgre too, but have not tested).

This is a query with a literal in aggregate:

SELECT uid FROM users GROUP BY 'literal', uid

This is without it:

SELECT uid FROM uers GROUP BY uid

Steps to reproduce

--

Proposed resolution

Skip constant values and expressions when generating the aggregation part of the query.

Remaining tasks

Review
RTBC
Commit

User interface changes

None.

API changes

None.

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component

views.module

Created by

🇪🇸Spain david_garcia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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