[pgsql-jp: 39890] Lead関数で第3引数を指定すると文法エラーになる。

postgresqlmailabcd @ mail.goo.ne.jp postgresqlmailabcd @ mail.goo.ne.jp
2009年 6月 19日 (金) 12:24:57 JST


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

環境 8.4beta2 windows版

create table tes(
ID smallint,
SortKey smallint,
Val smallint);

insert into tes values(1,1,   1);
insert into tes values(1,2,   2);
insert into tes values(1,3,   4);
insert into tes values(1,4,   8);
insert into tes values(2,1,  16);
insert into tes values(2,2,  32);
insert into tes values(2,3,  64);
insert into tes values(2,4, 128);
insert into tes values(3,1,   1);
insert into tes values(3,3,   1);
insert into tes values(3,5,   2);
insert into tes values(4,1,null);
insert into tes values(4,2, 123);
insert into tes values(4,3,null);

--これは、エラーになりません
select ID,SortKey,Val,
Lead(Val,2) over(partition by ID order by SortKey)
  from tes;

--Lead関数で第3引数を指定すると下記のエラーが発生します。
select ID,SortKey,Val,
Lead(Val,2,999) over(partition by ID order by SortKey)
  from tes;

postgres=# select ID,SortKey,Val,
postgres-# Lead(Val,2,999) over(partition by ID order by SortKey)
postgres-#   from tes;
ERROR:  function lead(smallint, integer, integer) does not exist
LINE 2: Lead(Val,2,999) over(partition by ID order by SortKey)
        ^
HINT:  No function matches the given name and argument types. You might need to
add explicit type casts.
postgres=#

--これだとエラーになりません。
with w(ID,SortKey,Val) as(
select 1,1,   1 union all
select 1,2,   2 union all
select 1,3,   4 union all
select 1,4,   8 union all
select 2,1,  16 union all
select 2,2,  32 union all
select 2,3,  64 union all
select 2,4, 128 union all
select 3,1,   1 union all
select 3,3,   1 union all
select 3,5,   2 union all
select 4,1,null union all
select 4,2, 123 union all
select 4,3,null)
select ID,SortKey,Val,
Lead(Val,2,999) over(partition by ID order by SortKey)
  from w;

マニュアルを読む限り問題なさそうですが・・・
http://developer.postgresql.org/pgdocs/postgres/functions-window.html


************************************************************
OracleSQLパズル
http://oraclesqlpuzzle.hp.infoseek.co.jp/




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