Re: array_agg() NULL Handling

Поиск
Список
Период
Сортировка
От David E. Wheeler
Тема Re: array_agg() NULL Handling
Дата
Msg-id 63C3C7B1-5C2A-4EC4-A4F6-856FD2949434@kineticode.com
обсуждение исходный текст
Ответ на Re: array_agg() NULL Handling  (Thom Brown <thom@linux.com>)
Список pgsql-hackers
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 all the standard ones do.) 
>>
>> -- http://developer.postgresql.org/pgdocs/postgres/sql-expressions.html#SYNTAX-AGGREGATES
>>
>> That, however, is not true of array_agg():
>>
>> try=# CREATE TABLE foo(id int);
>> CREATE TABLE
>> try=# INSERT INTO foo values(1), (2), (NULL), (3);
>> INSERT 0 4
>> try=# select array_agg(id) from foo;
>>  array_agg
>> ──────────────
>>  {1,2,NULL,3}
>> (1 row)
>>
>> So are the docs right, or is array_agg() right?
>
> I think it might be both.  array_agg doesn't return NULL, it returns
> an array which contains NULL.

No, string_agg() doesn't work this way, for example:

select string_agg(id::text, ',') from foo;string_agg
────────────1,2,3
(1 row)

Note that it's not:

select string_agg(id::text, ',') from foo;string_agg
────────────1,2,,3
(1 row)

Best,

David



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: array_agg() NULL Handling
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Interruptible sleeps (was Re: CommitFest 2009-07: Yay, Kevin! Thanks, reviewers!)