File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
src/ORM/Query/AST/Functions Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1515 * @see https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE
1616 *
1717 * @example ARRAY_AGG(entity.field)
18+ * @example ARRAY_AGG(DISTINCT entity.field)
1819 * @example ARRAY_AGG(entity.field) FILTER (WHERE entity.field IS NOT NULL)
20+ * @example ARRAY_AGG(DISTINCT entity.field) FILTER (WHERE entity.field IS NOT NULL)
1921 */
2022final class ArrayAgg extends AggregateWithFilterFunction
2123{
24+ private bool $ distinct = false ;
25+
2226 private Node $ expr ;
2327
2428 public function parseFunction (Parser $ parser ): void
2529 {
2630 $ parser ->match (Lexer::T_IDENTIFIER );
2731 $ parser ->match (Lexer::T_OPEN_PARENTHESIS );
32+
33+ $ lexer = $ parser ->getLexer ();
34+ if ($ lexer ->isNextToken (Lexer::T_DISTINCT )) {
35+ $ parser ->match (Lexer::T_DISTINCT );
36+ $ this ->distinct = true ;
37+ }
38+
2839 $ this ->expr = $ parser ->StringPrimary ();
2940 $ parser ->match (Lexer::T_CLOSE_PARENTHESIS );
3041 }
3142
3243 public function getFunctionSql (SqlWalker $ sqlWalker ): string
3344 {
34- return " ARRAY_AGG( { $ this ->expr ->dispatch ($ sqlWalker )} ) " ;
45+ return sprintf ( ' ARRAY_AGG(%s%s) ' , $ this ->distinct ? ' DISTINCT ' : '' , $ this -> expr ->dispatch ($ sqlWalker )) ;
3546 }
3647}
Original file line number Diff line number Diff line change 1515 * @see https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE
1616 *
1717 * @example JSON_AGG(entity.field)
18+ * @example JSON_AGG(DISTINCT entity.field)
1819 * @example JSON_AGG(entity.field) FILTER (WHERE entity.field IS NOT NULL)
20+ * @example JSON_AGG(DISTINCT entity.field) FILTER (WHERE entity.field IS NOT NULL)
1921 */
2022final class JsonAgg extends AggregateWithFilterFunction
2123{
24+ private bool $ distinct = false ;
25+
2226 private Node $ expr ;
2327
2428 public function parseFunction (Parser $ parser ): void
2529 {
2630 $ parser ->match (Lexer::T_IDENTIFIER );
2731 $ parser ->match (Lexer::T_OPEN_PARENTHESIS );
32+
33+ $ lexer = $ parser ->getLexer ();
34+ if ($ lexer ->isNextToken (Lexer::T_DISTINCT )) {
35+ $ parser ->match (Lexer::T_DISTINCT );
36+ $ this ->distinct = true ;
37+ }
38+
2839 $ this ->expr = $ parser ->StringPrimary ();
2940 $ parser ->match (Lexer::T_CLOSE_PARENTHESIS );
3041 }
3142
3243 public function getFunctionSql (SqlWalker $ sqlWalker ): string
3344 {
34- return " JSON_AGG( { $ this ->expr ->dispatch ($ sqlWalker )} ) " ;
45+ return sprintf ( ' JSON_AGG(%s%s) ' , $ this ->distinct ? ' DISTINCT ' : '' , $ this -> expr ->dispatch ($ sqlWalker )) ;
3546 }
3647}
Original file line number Diff line number Diff line change 1919 */
2020final class JsonbAgg extends AggregateWithFilterFunction
2121{
22+ private bool $ distinct = false ;
23+
2224 private Node $ expr ;
2325
2426 public function parseFunction (Parser $ parser ): void
2527 {
2628 $ parser ->match (Lexer::T_IDENTIFIER );
2729 $ parser ->match (Lexer::T_OPEN_PARENTHESIS );
30+
31+ $ lexer = $ parser ->getLexer ();
32+ if ($ lexer ->isNextToken (Lexer::T_DISTINCT )) {
33+ $ parser ->match (Lexer::T_DISTINCT );
34+ $ this ->distinct = true ;
35+ }
36+
2837 $ this ->expr = $ parser ->StringPrimary ();
2938 $ parser ->match (Lexer::T_CLOSE_PARENTHESIS );
3039 }
3140
3241 public function getFunctionSql (SqlWalker $ sqlWalker ): string
3342 {
34- return " JSON_AGG( { $ this ->expr ->dispatch ($ sqlWalker )} ) " ;
43+ return sprintf ( ' JSONB_AGG(%s%s) ' , $ this ->distinct ? ' DISTINCT ' : '' , $ this -> expr ->dispatch ($ sqlWalker )) ;
3544 }
3645}
You can’t perform that action at this time.
0 commit comments