Re: Creating a non-strict custom aggregate that initializes to the first value

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Creating a non-strict custom aggregate that initializes to the first value
Дата
Msg-id 15009.1427896036@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Creating a non-strict custom aggregate that initializes to the first value  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thu, Mar 26, 2015 at 1:49 PM, Timothy Garnett <tgarnett@panjiva.com>
> wrote:
>> but if that is declared strict then it would take the first non-null value
>> and return A in my second example, if declared non-strict then the initial
>> state would be fed as null rather then the first value. Is there a way to
>> declare the function non-strict (so that null values are passed) but still
>> have it initialize to the first value like it would if it was strict?

> You want NULL to both mean "not initialized" and "unknown value" which is
> impossible and SQL does not provide any other universal literal that means
> one or the other.

Yeah.  You need distinct representations for "nothing seen yet" and "saw a
NULL"; the built-in behavior doesn't suffice for this.

One idea is for the state value to be of anyarray type: initially null,
and a one-element array containing the first input value once you've seen
that.

It strikes me though that this aggregate is ill-defined by nature.  In
particular, if you're going to treat NULL as being a real data value,
then what're you gonna return when there were no input rows?  You won't be
able to distinguish "no input rows" from "first input row had a NULL".
Maybe you should rethink whatever activity you were wanting it for.

            regards, tom lane


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

Предыдущее
От: TonyS
Дата:
Сообщение: Re: Would like to know how analyze works technically
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: How to diagnose max_locks_per_transaction is about to be exhausted?