mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
Add group_concat aggregator function
Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
parent
29dffd7e7f
commit
79b3df00f8
4 changed files with 34 additions and 0 deletions
|
|
@ -49,6 +49,10 @@ class FunctionBuilder implements IFunctionBuilder {
|
|||
return new QueryFunction('CONCAT(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ')');
|
||||
}
|
||||
|
||||
public function substring($input, $start, $length = null): IQueryFunction {
|
||||
if ($length) {
|
||||
return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
|
||||
|
|
|
|||
|
|
@ -72,4 +72,11 @@ class OCIFunctionBuilder extends FunctionBuilder {
|
|||
|
||||
return parent::least($x, $y);
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
if (is_null($separator)) {
|
||||
return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr));
|
||||
}
|
||||
return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . ", '$separator')");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,4 +30,11 @@ class PgSqlFunctionBuilder extends FunctionBuilder {
|
|||
public function concat($x, $y): IQueryFunction {
|
||||
return new QueryFunction('(' . $this->helper->quoteColumnName($x) . ' || ' . $this->helper->quoteColumnName($y) . ')');
|
||||
}
|
||||
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
|
||||
if (is_null($separator)) {
|
||||
return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr));
|
||||
}
|
||||
return new QueryFunction('string_agg(' . $this->helper->quoteColumnName($expr) . ", '$separator')");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,22 @@ interface IFunctionBuilder {
|
|||
*/
|
||||
public function concat($x, $y): IQueryFunction;
|
||||
|
||||
/**
|
||||
* Returns a string which is the concatenation of all non-NULL values of X
|
||||
*
|
||||
* Usage examples:
|
||||
*
|
||||
* groupConcat('column') -- with comma as separator (default separator)
|
||||
*
|
||||
* groupConcat('column', ';') -- with different separator
|
||||
*
|
||||
* @param string|ILiteral|IParameter|IQueryFunction $expr The expression to group
|
||||
* @param string|null $separator The separator
|
||||
* @return IQueryFunction
|
||||
* @since 24.0.0
|
||||
*/
|
||||
public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
|
||||
|
||||
/**
|
||||
* Takes a substring from the input string
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue