Merge pull request #3092 from Icinga/fix/postgresql-groupby

pogsql: Group by custom variables when querying them
This commit is contained in:
lippserd 2017-11-16 20:23:06 +01:00 committed by GitHub
commit 5c1d67a1ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -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)