[pgsql-jp: 39897] window関数のarray_agg関数(order by指定)の結果がおかしい

postgresqlmailabcd @ mail.goo.ne.jp postgresqlmailabcd @ mail.goo.ne.jp
2009年 6月 22日 (月) 21:44:08 JST


window関数でいろいろ試していたらこんな現象に遭遇しました。
原因が分かる方がおられましたら、教えてください。

環境 8.4beta2 windows版

with w(sortKey,Val) as(
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 4,'d' union all
select 5,'e')
select
array_agg(Val) over() as strAgg1,
array_agg(Val) over(order by sortKey) as strAgg2,
(select array_agg(b.Val)
   from w b
  where b.sortKey <= a.sortKey) as strAgg3
  from w a;

   stragg1   |   stragg2   |   stragg3
-------------+-------------+-------------
 {a,b,c,d,e} | {a}         | {a}
 {a,b,c,d,e} | {b,b}       | {a,b}
 {a,b,c,d,e} | {c,c,c}     | {a,b,c}
 {a,b,c,d,e} | {d,d,d,d}   | {a,b,c,d}
 {a,b,c,d,e} | {e,e,e,e,e} | {a,b,c,d,e}

stragg2とstragg3が一致するのが正しい結果ではないでしょうか?
配列の要素が違います。

*******************************************************
明智重蔵
http://oraclesqlpuzzle.hp.infoseek.co.jp/blog.html



pgsql-jp メーリングリストの案内