FILTER clause for non-aggregate window functions
От | Андрей Жиденков |
---|---|
Тема | FILTER clause for non-aggregate window functions |
Дата | |
Msg-id | CAN=gQ4AG_XxuTSq2brj3GY_MK-Qc+KwnETQiMXGmycsgy_Mbhw@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: FILTER clause for non-aggregate window functions
|
Список | pgsql-sql |
I need to find the first date value in widow which meets certain conditions. In my case I use min() function with CASE like this:
SELECT min(CASE WHEN <conditions> THEN <date_field> end) OVER (PARTITION BY .. ORDER BY <date_field> ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING)
But this is too slow mainly because of min() should read all tuples in window, I guess. So I tried to use first_value() function like this:
SELECT first_value(<date_field>) FILTER(WHERE <conditions>) OVER (PARTITION BY .. ORDER BY <date_field> ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING)
But I got this error:
FILTER is not implemented for non-aggregate window functions
Andrey Zhidenkov
В списке pgsql-sql по дате отправления: