mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
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
This commit is contained in:
parent
166f27b947
commit
d11519ac49
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user