NULL input for array_agg()?
NULL input for array_agg()?
От:
Hitoshi Harada <umi.tanuki@gmail.com>
Дата:
Hi, During reviewing aggregates ORDER BY, I was reading spec and found description like: == snip == Of the rows in the aggregation, the following do not qualify: — If DISTINCT is specified, then redundant duplicates. — Every row in which the evaluates to the null value. == /snip == ... and array_agg() is among the functions that description above refers to. So I wonder if array_agg doesn't accept NULL input (with STRICT trans function). Did we discussed about this issue when implementing it for 8.4? Regards, -- Hitoshi Harada
Re: NULL input for array_agg()?
От:
Andrew Gierth <andrew@tao11.riddles.org.uk>
Дата:
>>>>> "Hitoshi" == Hitoshi Harada writes: Hitoshi> Hi, During reviewing aggregates ORDER BY, I was reading specHitoshi> and found description like: Hitoshi> == snip == Hitoshi> Of the rows in the aggregation, the following do not qualify:Hitoshi> — If DISTINCT is specified, then redundant duplicates.Hitoshi> — Every row in which the evaluates to the null value. Hitoshi> == /snip == Where did you find that? The SQL2008 last-call draft says this: 4) If is specified, then: a) Let TX be the single-column table that is the result of applying the to each row of T1 and eliminating null values. If one or more null values are eliminated, then a completion condition is raised: warning -- null value eliminated in set function. b) Case: i) If DISTINCT is specified, then let TXA be the result of eliminating redundant duplicate values from TX, using the comparison rules specified in Subclause 8.2, "", to identify the redundant duplicate values. ii) Otherwise, let TXA be TX. [more subclauses of rule (4) snipped as irrelevant] 8) If is specified, then: a) If is specified, then let K be the number of s; otherwise, let K be 0 (zero). b) Let TXA be the table of K+1 columns obtained by applying the immediately contained in the to each row of T1 to obtain the first column of TXA, and, for all i, 1 (one) i K, applying the simply contained in the i-th to each row of T1 to obtain the (i+1)-th column of TXA. c) Let TXA be ordered according to the values of the s found in the second through (K+1)-th columns of TXA. If K is 0 (zero), then the ordering of TXA is implementation-dependent. d) Let N be the number of rows in TXA. e) If N is greater than IDMC, then an exception condition is raised: data exception -- array data, right truncation. f) Let Ri, 1 (one) i N, be the rows of TXA according to the ordering of TXA. g) Case: i) If TXA is empty, then the result of is the null value. ii) Otherwise, the result of is an array of N elements such that for all i, 1 (one) i N, the value of the i-th element is the value of the first column of Ri. NOTE 267 -- Null values are not eliminated when computing . This, plus the optional , sets apart from s. array_agg is an (in fact the only such), whereas includes almost all the other single-arg aggregates (avg, min, max, etc.) -- Andrew (irc:RhodiumToad)
Re: NULL input for array_agg()?
От:
Hitoshi Harada <umi.tanuki@gmail.com>
Дата:
2009/11/15 Andrew Gierth : >>>>>> "Hitoshi" == Hitoshi Harada writes: > > Hitoshi> Hi, During reviewing aggregates ORDER BY, I was reading spec > Hitoshi> and found description like: > > Hitoshi> == snip == > > Hitoshi> Of the rows in the aggregation, the following do not qualify: > Hitoshi> — If DISTINCT is specified, then redundant duplicates. > Hitoshi> — Every row in which the evaluates to the null value. > > Hitoshi> == /snip == > > Where did you find that? In 4.15.4 Aggregate functions. But your snip clarified is special case. > NOTE 267 -- Null values are not eliminated when computing aggregate function>. This, plus the optional list>, sets apart from function>s. Regards, -- Hitoshi Harada