From d11519ac495aaa4fe7d522efa3eb9391792047b7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 16 Nov 2017 09:16:13 +0100 Subject: [PATCH] pogsql: Group by custom variables when querying them Custom variables added via the URL parameters addColumns or sort must be added to the GROUP BY list when using PostgreSQL. Credits to @nbuchwitz who came up with the initial fix for this. refs #1873 --- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 3a067bb3e..a43f59416 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -1163,6 +1163,14 @@ abstract class IdoQuery extends DbQuery foreach (new ColumnFilterIterator($this->columns) as $desiredAlias => $desiredColumn) { $alias = is_string($desiredAlias) ? $this->customAliasToAlias($desiredAlias) : $desiredColumn; + if ($this->isCustomVar($alias) && $this->getDatasource()->getDbType() === 'pgsql') { + $table = $this->customVars[$alias]; + if (! isset($groupedTables[$table])) { + $group[] = $this->getCustomvarColumnName($alias); + $groupedTables[$table] = true; + } + continue; + } $table = $this->aliasToTableName($alias); if ($table && !isset($groupedTables[$table]) && ( in_array($table, $joinedOrigins, true) || $this->getDatasource()->getDbType() === 'pgsql') @@ -1173,6 +1181,14 @@ abstract class IdoQuery extends DbQuery if (! empty($group) && $this->getDatasource()->getDbType() === 'pgsql') { foreach (new ColumnFilterIterator($this->orderColumns) as $alias) { + if ($this->isCustomVar($alias)) { + $table = $this->customVars[$alias]; + if (! isset($groupedTables[$table])) { + $group[] = $this->getCustomvarColumnName($alias); + $groupedTables[$table] = true; + } + continue; + } $table = $this->aliasToTableName($alias); if ($table && !isset($groupedTables[$table]) && !in_array($this->getMappedField($alias), $this->columns, true)