
Slope of the least-squares-fit linear equation determined by the ( X, Y) pairs Y-intercept of the least-squares-fit linear equation determined by the ( X, Y) pairs Number of input rows in which both expressions are nonnull Aggregate Functions for Statistics FunctionĪverage of the independent variable ( sum( X)/ N)Īverage of the dependent variable ( sum( Y)/ N) In all cases, null is returned if the computation is meaningless, for example when N is zero. (These are separated out merely to avoid cluttering the listing of more-commonly-used aggregates.) Where the description mentions N, it means the number of input rows for which all the input expressions are non-null. Table 9-50 shows aggregate functions typically used in statistical analysis. For example: SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab īut this syntax is not allowed in the SQL standard, and is not portable to other database systems. Alternatively, supplying the input values from a sorted subquery will usually work. This ordering is unspecified by default, but can be controlled by writing an ORDER BY clause within the aggregate call, as shown in Section 4.2.7. The aggregate functions array_agg, json_agg, jsonb_agg, json_object_agg, jsonb_object_agg, string_agg, and xmlagg, as well as similar user-defined aggregate functions, produce meaningfully different result values depending on the order of the input values. Will require effort proportional to the size of the table: PostgreSQL will need to scan either the entire table or the entirety of an index which includes all rows in the table. A query like: SELECT count(*) FROM sometable Note: Users accustomed to working with other SQL database management systems might be disappointed by the performance of the count aggregate when it is applied to the entire table. The coalesce function can be used to substitute zero or an empty array for null when necessary. In particular, sum of no rows returns null, not zero as one might expect, and array_agg returns null rather than an empty array when there are no input rows. It should be noted that except for count, these functions return a null value when no rows are selected. Sum of expression across all non-null input valuesĬoncatenation of non-null XML values (see also Section 9.14.1.7) Smallint, int, bigint, real, double precision, numeric, interval, or moneyīigint for smallint or int arguments, numeric for bigint arguments, otherwise the same as the argument data type Non-null input values concatenated into a string, separated by delimiter Minimum value of expression across all non-null input values Maximum value of expression across all non-null input values Number of input rows for which the value of expression is not nullĪggregates values, including nulls, as a JSON arrayĪggregates name/value pairs as a JSON object values can be null, but not namesĪny numeric, string, date/time, network, or enum type, or arrays of these types True if at least one input value is true, otherwise false True if all input values are true, otherwise false The bitwise OR of all non-null input values, or null if none The bitwise AND of all non-null input values, or null if none

The average (arithmetic mean) of all non-null input values Numeric for any integer-type argument, double precision for a floating-point argument, otherwise the same as the argument data type Smallint, int, bigint, real, double precision, numeric, or interval Input arrays concatenated into array of one higher dimension (inputs must all have same dimensionality, and cannot be empty or null) Input values, including nulls, concatenated into an array General-Purpose Aggregate Functions Function Let’s take some examples of using the DATEADD() function.Table 9-49. The function DATEADD() function returns a new date value after adding the value to the date_part.

The following table lists the valid values of date_part: date_part input_date is a literal date value or an expression which can resolve to a value of type DATE, DATETIME, DATETIMEOFFSET, DATETIME2, SMALLATETIME, or TIME.It will not round the number in this case. If the value evaluates to a decimal or float, the function DATEADD() will truncate the decimal fraction part. value is an integer number to be added to the date_part of the input_date.(See the valid date parts in the table below) date_part is the part of date to which the DATEADD() function will add the value.

The DATEADD() function accepts three arguments: DATEADD (date_part, value, input_date )Ĭode language: SQL (Structured Query Language) ( sql )
