Re: [HACKERS] array_agg() NULL Handling

2010-10-01 Thread David E. Wheeler
On Sep 1, 2010, at 11:52 AM, Pavel Stehule wrote: >> regression=# create or replace function array_agg_transfn_strict(internal, >> anyelement) returns internal as 'array_agg_transfn' language internal >> immutable; >> CREATE FUNCTION >> regression=# create aggregate array_agg_strict(anyelement)

Re: [HACKERS] array_agg() NULL Handling

2010-09-02 Thread Dimitri Fontaine
"David E. Wheeler" writes: > On Sep 1, 2010, at 10:52 AM, Thom Brown wrote: > ould appreciate the recipe for removing the NULLs. >>> >>> WHERE clause :P >> >> There may be cases where that's undesirable, such as there being more >> than one aggregate in the SELECT list, or the column being

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Pavel Stehule
2010/9/1 Tom Lane : > Pavel Stehule writes: >> 2010/9/1 Tom Lane : >>> Well, you can build your own version of array_agg with the same >>> implementation, except you mark the transition function as strict ... > >> I am checking this now, and it is not possible - it needs a some >> initial value an

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Tom Lane
Pavel Stehule writes: > 2010/9/1 Tom Lane : >> Well, you can build your own version of array_agg with the same >> implementation, except you mark the transition function as strict ... > I am checking this now, and it is not possible - it needs a some > initial value and there isn't possible to se

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Pavel Stehule
2010/9/1 Tom Lane : > "David E. Wheeler" writes: >> On Sep 1, 2010, at 11:09 AM, Pavel Stehule wrote: >>> Then you can eliminate NULLs with simple function > >> Kind of defeats the purpose of the efficiency of the aggregate. > > Well, you can build your own version of array_agg with the same > imp

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Tom Lane
"David E. Wheeler" writes: > On Sep 1, 2010, at 11:09 AM, Pavel Stehule wrote: >> Then you can eliminate NULLs with simple function > Kind of defeats the purpose of the efficiency of the aggregate. Well, you can build your own version of array_agg with the same implementation, except you mark th

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Tom Lane
"David E. Wheeler" writes: > On Sep 1, 2010, at 10:30 AM, Tom Lane wrote: >> Most aggregate functions ignore null inputs, so that rows in which >> one or more of the expression(s) yield null are discarded. (This >> can be assumed to be true, unless otherwise specified, for all >> built-in aggrega

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 11:09 AM, Pavel Stehule wrote: > Then you can eliminate NULLs with simple function > > CREATE OR REPLACE FUNCTION remove_null(anyarray) > RETURNS anyarray AS $$ > SELECT ARRAY(SELECT x FROM unnest($1) g(x) WHERE x IS NOT NULL) > $$ LANGUAGE sql; Kind of defeats the purpose of

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Pavel Stehule
2010/9/1 Thom Brown : > On 1 September 2010 18:47, David Fetter wrote: >> On Wed, Sep 01, 2010 at 08:16:41AM -0700, David Wheeler wrote: >>> On Sep 1, 2010, at 12:30 AM, Pavel Stehule wrote: >>> >>> > Docs is wrong :) I like current implementation.  You can remove a >>> > NULLs from aggregation ve

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 10:30 AM, Tom Lane wrote: > Hm, actually the whole para needs work. It was designed at a time when > DISTINCT automatically discarded nulls, which isn't true anymore, and > that fact was patched-in in a very awkward way too. Perhaps something > like > >The first form of a

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 10:52 AM, Thom Brown wrote: >>> ould appreciate the recipe for removing the NULLs. >> >> WHERE clause :P > > There may be cases where that's undesirable, such as there being more > than one aggregate in the SELECT list, or the column being grouped on > needing to return rows r

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Thom Brown
On 1 September 2010 18:47, David Fetter wrote: > On Wed, Sep 01, 2010 at 08:16:41AM -0700, David Wheeler wrote: >> On Sep 1, 2010, at 12:30 AM, Pavel Stehule wrote: >> >> > Docs is wrong :) I like current implementation.  You can remove a >> > NULLs from aggregation very simply, but different dire

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David Fetter
On Wed, Sep 01, 2010 at 08:16:41AM -0700, David Wheeler wrote: > On Sep 1, 2010, at 12:30 AM, Pavel Stehule wrote: > > > Docs is wrong :) I like current implementation. You can remove a > > NULLs from aggregation very simply, but different direction isn't > > possible > > Would appreciate the re

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Tom Lane
"David E. Wheeler" writes: > On Sep 1, 2010, at 10:12 AM, Tom Lane wrote: >> Even more to the point, should we deliberately make this vaguer so that >> we aren't finding ourselves with obsolete text again and again? You can >> bet that people adding new aggregates in the future aren't going to >>

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 10:12 AM, Tom Lane wrote: > I think when that text was written, it was meant to imply "all the > aggregates defined in SQL92". There seems to be a lot of confusion > in this thread about whether "standard" means "defined by SQL spec" > or "built-in in Postgres". Should we try

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Tom Lane
"David E. Wheeler" writes: > *** 1543,1549 > The first form of aggregate expression invokes the aggregate > across all input rows for which the given expression(s) yield > non-null values. (Actually, it is up to the aggregate function > ! whether to ignore null values o

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 12:30 AM, Pavel Stehule wrote: >> So are the docs right, or is array_agg() right? > > Docs is wrong :) I like current implementation. You can remove a NULLs > from aggregation very simply, but different direction isn't possible Patch: diff --git a/doc/src/sgml/syntax.sgml b/d

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 1:06 AM, Thom Brown wrote: >> I think it might be both. array_agg doesn't return NULL, it returns >> an array which contains NULL. > > The second I wrote that, I realised it was b*ll%$ks, as I was still in > the process of waking up. I know that feeling. /me sips his coffee

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Sep 1, 2010, at 12:30 AM, Pavel Stehule wrote: > Docs is wrong :) I like current implementation. You can remove a NULLs > from aggregation very simply, but different direction isn't possible Would appreciate the recipe for removing the NULLs. Best, David -- Sent via pgsql-hackers mailing

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Thom Brown
On 1 September 2010 07:56, Thom Brown wrote: > On 1 September 2010 06:45, David E. Wheeler wrote: >> The aggregate docs say: >> >>> The first form of aggregate expression invokes the aggregate across all >>> input rows for which the given expression(s) yield non-null values. >>> (Actually, it i

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread Pavel Stehule
2010/9/1 David E. Wheeler : > The aggregate docs say: > >> The first form of aggregate expression invokes the aggregate across all >> input rows for which the given expression(s) yield non-null values. >> (Actually, it is up to the aggregate function whether to ignore null values >> or not — but

Re: [HACKERS] array_agg() NULL Handling

2010-09-01 Thread David E. Wheeler
On Aug 31, 2010, at 11:56 PM, Thom Brown wrote: >>> The first form of aggregate expression invokes the aggregate across all >>> input rows for which the given expression(s) yield non-null values. >>> (Actually, it is up to the aggregate function whether to ignore null values >>> or not — but al

Re: [HACKERS] array_agg() NULL Handling

2010-08-31 Thread Thom Brown
On 1 September 2010 06:45, David E. Wheeler wrote: > The aggregate docs say: > >> The first form of aggregate expression invokes the aggregate across all >> input rows for which the given expression(s) yield non-null values. >> (Actually, it is up to the aggregate function whether to ignore null

[HACKERS] array_agg() NULL Handling

2010-08-31 Thread David E. Wheeler
The aggregate docs say: > The first form of aggregate expression invokes the aggregate across all input > rows for which the given expression(s) yield non-null values. (Actually, it > is up to the aggregate function whether to ignore null values or not — but > all the standard ones do.) -- ht