drupal

Errores de GROUP BY en Drupal con PostgreSQL

­Algunas vistas en Drupal generan un error como este cuando se usa u­na ba­se ­de datos PostgreSQL:
­
Query failed: ERRO­R: column "xxx.xxx" must appear in the GROUP BY clause or be used in an aggregate function...
­

La solución consiste en aplicar este parche al archivo views_query.inc.

<?php
//Make fscking sure we've all selected fields in group by to avoid breaking PostgreSQL.
//
//$this-&gt;field already has aliases and other cruft. Get rid of 'em first.
//Besides, we should omit fields that are just aggregate functions.
//
//First, get rid of aliases.
$groupbyfields preg_replace('/\ AS.*/'''$this-&gt;fields);
//If selection is surroundend by DISTINCT, get rid of it.
$groupbyfields preg_replace('/DISTINCT\(/'''$groupbyfields);
$groupbyfields preg_replace('/\)/'''$groupbyfields);
//If we still have opening parenthesis, the field is an aggregate function.
//Drop it altogether!
$groupbyfields preg_grep('/.*\(/'$groupbyfieldsPREG_GREP_INVERT);
foreach(
$groupbyfields as $field) {
    if (!(
in_array($field$this-&gt;groupby))) {
    
$this-&gt;add_groupby($field);
  }
}

?>