drupal
Errores de GROUP BY en Drupal con PostgreSQL
Algunas vistas en Drupal generan un error como este cuando se usa una base de datos PostgreSQL:
La solución consiste en aplicar este parche al archivo views_query.inc.
Query failed: ERROR: 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->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->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('/.*\(/', $groupbyfields, PREG_GREP_INVERT);
foreach($groupbyfields as $field) {
if (!(in_array($field, $this->groupby))) {
$this->add_groupby($field);
}
}
?>
