Skip to content

Commit 0a947ab

Browse files
JSON_ARRAY_AGG (#1113)
Co-authored-by: Quan <[email protected]>
1 parent 481b39a commit 0a947ab

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: JSON_ARRAY_AGG
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="Introduced or updated: v1.2.595"/>
8+
9+
Converts values into a JSON array while skipping NULLs.
10+
11+
## Syntax
12+
13+
```sql
14+
JSON_ARRAY_AGG(<expr>)
15+
```
16+
17+
## Return Type
18+
19+
JSON array.
20+
21+
## Examples
22+
23+
```sql
24+
CREATE TABLE d (
25+
a DECIMAL(10, 2),
26+
b STRING,
27+
c INT,
28+
d VARIANT,
29+
e ARRAY(STRING)
30+
);
31+
32+
INSERT INTO d VALUES
33+
(20, 'abc', NULL, '{"k":"v"}', ['a','b']),
34+
(10, 'de', 100, 'null', []),
35+
(4.23, NULL, 200, '"uvw"', ['x','y']),
36+
(5.99, 'xyz', 300, '[1,2,3]', ['z']);
37+
38+
SELECT
39+
json_array_agg(a) AS aggregated_a,
40+
json_array_agg(b) AS aggregated_b,
41+
json_array_agg(c) AS aggregated_c,
42+
json_array_agg(d) AS aggregated_d,
43+
json_array_agg(e) AS aggregated_e
44+
FROM d;
45+
46+
-[ RECORD 1 ]-----------------------------------
47+
aggregated_a: [20.0,10.0,4.23,5.99]
48+
aggregated_b: ["abc","de","xyz"]
49+
aggregated_c: [100,200,300]
50+
aggregated_d: [{"k":"v"},null,"uvw",[1,2,3]]
51+
aggregated_e: [["a","b"],[],["x","y"],["z"]]
52+
```

docs/en/sql-reference/20-sql-functions/07-aggregate-functions/index.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,8 @@
22
title: 'Aggregate Functions'
33
---
44

5-
Aggregate functions are essential tools in SQL that allow you to perform calculations on a set of values and return a single result.
5+
import IndexOverviewList from '@site/src/components/IndexOverviewList';
66

7-
These functions help you extract and summarize data from databases to gain valuable insights.
7+
This section provides reference information for the aggregate functions in Databend.
88

9-
| Function Name | What It Does |
10-
|---------------------------------------------------------------------|------------------------------------------------------------------------------|
11-
| [ANY](aggregate-any.md) | Checks if any row meets the specified condition |
12-
| [APPROX_COUNT_DISTINCT](aggregate-approx-count-distinct.md) | Estimates the number of distinct values with HyperLogLog |
13-
| [ARG_MAX](aggregate-arg-max.md) | Finds the arg value for the maximum val value |
14-
| [ARG_MIN](aggregate-arg-min.md) | Finds the arg value for the minimum val value |
15-
| [AVG_IF](aggregate-avg-if.md) | Calculates the average for rows meeting a condition |
16-
| [ARRAY_AGG](aggregate-array-agg.md) | Converts all the values of a column to an Array |
17-
| [AVG](aggregate-avg.md) | Calculates the average value of a specific column |
18-
| [COUNT_DISTINCT](aggregate-count-distinct.md) | Counts the number of distinct values in a column |
19-
| [COUNT_IF](aggregate-count-if.md) | Counts rows meeting a specified condition |
20-
| [COUNT](aggregate-count.md) | Counts the number of rows that meet certain criteria |
21-
| [COVAR_POP](aggregate-covar-pop.md) | Returns the population covariance of a set of number pairs |
22-
| [COVAR_SAMP](aggregate-covar-samp.md) | Returns the sample covariance of a set of number pairs |
23-
| [GROUP_ARRAY_MOVING_AVG](aggregate-group-array-moving-avg.md) | Returns an array with elements calculates the moving average of input values |
24-
| [GROUP_ARRAY_MOVING_SUM](aggregate-group-array-moving-sum.md) | Returns an array with elements calculates the moving sum of input values |
25-
| [KURTOSIS](aggregate-kurtosis.md) | Calculates the excess kurtosis of a set of values |
26-
| [MAX_IF](aggregate-max-if.md) | Finds the maximum value for rows meeting a condition |
27-
| [MAX](aggregate-max.md) | Finds the largest value in a specific column |
28-
| [MEDIAN](aggregate-median.md) | Calculates the median value of a specific column |
29-
| [MEDIAN_TDIGEST](aggregate-median-tdigest.md) | Calculates the median value of a specific column using t-digest algorithm |
30-
| [MIN_IF](aggregate-min-if.md) | Finds the minimum value for rows meeting a condition |
31-
| [MIN](aggregate-min.md) | Finds the smallest value in a specific column |
32-
| [QUANTILE_CONT](aggregate-quantile-cont.md) | Calculates the interpolated quantile for a specific column |
33-
| [QUANTILE_DISC](aggregate-quantile-disc.md) | Calculates the quantile for a specific column |
34-
| [QUANTILE_TDIGEST](aggregate-quantile-tdigest.md) | Calculates the quantile using t-digest algorithm |
35-
| [QUANTILE_TDIGEST_WEIGHTED](aggregate-quantile-tdigest-weighted.md) | Calculates the quantile with weighted using t-digest algorithm |
36-
| [RETENTION](aggregate-retention.md) | Calculates retention for a set of events |
37-
| [SKEWNESS](aggregate-skewness.md) | Calculates the skewness of a set of values |
38-
| [STDDEV_POP](aggregate-stddev-pop.md) | Calculates the population standard deviation of a column |
39-
| [STDDEV_SAMP](aggregate-stddev-samp.md) | Calculates the sample standard deviation of a column |
40-
| [STRING_AGG](aggregate-string-agg.md) | Converts all the non-NULL values to String, separated by the delimiter |
41-
| [SUM_IF](aggregate-sum-if.md) | Adds up the values meeting a condition of a specific column |
42-
| [SUM](aggregate-sum.md) | Adds up the values of a specific column |
43-
| [WINDOW_FUNNEL](aggregate-windowfunnel.md) | Analyzes user behavior in a time-ordered sequence of events |
44-
| [HISTOGRAM](aggregate-histogram.md) | Analyzes value distribution of a specific column |
9+
<IndexOverviewList />

0 commit comments

Comments
 (0)