Adding escaping for the GROUP BY fields broke ROLLUP support

Created on 21 February 2023, over 1 year ago
Updated 21 February 2024, 4 months ago

Problem/Motivation

By fixing ๐Ÿ› Select queries do not escape the GROUP BY fields Fixed , the support for the ROLLUP modifier in a GROUP BY clause has been removed.

After updating from Drupal 9.5.2 to Drupal 9.5.3, all my queries using ROLLUP stopped working.

Steps to reproduce

Using the following query and a Postgresql database :

$query = \Drupal::database()->select('users_field_data', 'u');
$query->addExpression('COUNT(u.uid)', 'count');
$query->groupBy('ROLLUP ("u"."status", "u"."langcode")');

dpm((string) $query);

we obtain the following results :

  • Drupal 9.5.2 : SELECT COUNT(u.uid) AS "count" FROM {users_field_data} "u" GROUP BY ROLLUP ("u"."status", "u"."langcode") OK ๐Ÿ‘
  • Drupal 9.5.3 : SELECT COUNT(u.uid) AS "count" FROM {users_field_data} "u" GROUP BY "ROLLUPu"."statusu"."langcode" KO ๐Ÿ‘Ž

Proposed resolution

Modify the SelectInterface::groupBy($field) method to add a new optionnal parameter : SelectInterface::groupBy($field, $isExpression = FALSE).

The new $isExpression parameter is used to specify if the group by field is an expression or not.

Remaining tasks

Items in the MR
Question in #24

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Databaseย  โ†’

Last updated 1 day ago

  • Maintained by
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands @daffie
Created by

๐Ÿ‡จ๐Ÿ‡ญSwitzerland epieddy

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

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024