Re: Rows From but with Subqueries (or a cleaner non-array-using alternative)?

Поиск
Список
Период
Сортировка
От Michael Lewis
Тема Re: Rows From but with Subqueries (or a cleaner non-array-using alternative)?
Дата
Msg-id CAHOFxGqfT8vDAx0LtOv+osgmUnbFmH8XvhP2-PfBo8ZQENmDug@mail.gmail.com
обсуждение исходный текст
Ответ на Rows From but with Subqueries (or a cleaner non-array-using alternative)?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
In pseudo code, group_index is defined as:
case when 
LAG(v) OVER (ORDER BY i) = v then lag(i) ELSE i END, right?

If you have that in the first cte instead of the start/end business, then you can just select vals, group number, and row_num over that new grouping, right?

Something like this?


WITH vals (i,v) AS (VALUES (0,1),(1,0),(2,0),(3,1),(4,0),(5,0),(6,1),(7,1),(8,0),(9,1)),
grouped_vals AS (SELECT *,
case when LAG(v) OVER (ORDER BY i) = v then lag(i) OVER (ORDER BY i) ELSE i END AS group_index
FROM vals
)
select *, row_number() OVER (PARTITION BY group_index ORDER BY i)
from grouped_vals
where v = 0;

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

Предыдущее
От: Michael Lewis
Дата:
Сообщение: Re: increasing effective_cache_size slows down join queries by a factor of 4000x
Следующее
От: Shaozhong SHI
Дата:
Сообщение: Turn a json column into a table