Aggregate functions¶
The REST API has aggregate functions. Each aggregate function can receive a set of values for each argument and return a single-value result for a set of input values. These functions are similar to those seen in ANSI SQL queries, which use the COUNT()
function, the MAX()
function, and so on.
General structure¶
You can include REST API aggregate functions in your HTTP request and receive a response in JSON object format. The HTTP requests must use the POST method, although the operations are idempotent.
Use the following parameter:
Parameter 1: action
Invoke the aggregate functions.
Value:
aggregate
Type: System string. Required.
Data 1: op
Specify the aggregate function, the input values, and the variable name for the output value in the data value. The data value is a JSON array in which you can invoke multiple aggregate functions in a single request.
Example value: The following JSON array shows the typical structure of a data value for invoking multiple aggregate functions:
[
{
"operation": <aggregate function 1>,
"fieldname": <input values 1>,
"outputname": <output variable name 1>
},
{
"operation": <aggregate function 2>,
"fieldname": <input values 2>,
"outputname": <output variable name 2>
},
...
]
Type: Array.
Data 1.1: op
> operation
Specify the aggregate function.
Value: The following is the available values:
Aggregate function |
|
---|---|
COUNT() |
|
MAX() |
|
SUM() |
|
For more information about the aggregate functions, see :ref:COUNT()
, MAX(), and SUM().
Type: System string. Required.
Data 1.2: op
> fieldname
The names of the target objects that you want to use for arguments of the aggregate function.
Example value:
pk
Type: String. Required.
Data 1.3: op
> outputname
The key name for the output key-value pair.
Example value: countPrimaryKeys
Type: String. Required.
COUNT()¶
The COUNT()
function returns the number of objects.
This operation is equivalent to the following ANSI SQL query:
SELECT COUNT(primary_key) FROM table
SUM()¶
The SUM()
function returns the sum of a set of numbers.
This operation is equivalent to the following ANSI SQL query:
SELECT SUM(transfer_size) FROM table
MAX()¶
The MAX()
function returns the maximum value in a set of values in a group.
This operation is equivalent to the following ANSI SQL query:
SELECT MAX(transfer_size) FROM table
GROUP clause¶
You can use the group
clause to divides selected rows into groups such that the rows of each group have matching values in one or more columns or expressions. The group
clause is equivalent to the GROUP BY
clause in ANSI SQL.
Data 2: group
Specify a value to apply to the group
clause.
Example value:
["pk"]
Type: Array.
This operation is equivalent to the following ANSI SQL query:
SELECT COUNT(primary_key) FROM table GROUP BY pk