File: opt_window.sql

package info (click to toggle)
plr 1%3A8.4.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,172 kB
  • sloc: ansic: 4,742; sql: 629; sh: 357; makefile: 78; perl: 20
file content (14 lines) | stat: -rw-r--r-- 615 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
create or replace function fast_win(a int4, b bigint) returns bool AS $$
##is.null(farg2) || pg.throwerror('Constants shall not be passes with the frame')
  identical(parent.frame(), .GlobalEnv) && pg.throwerror('Parent env is global')
  exists('plr_window_frame', parent.frame(), inherits=FALSE) || pg.throwerror('No window frame data found')
  a == farg1[prownum]
$$ window language plr;

select s, p, fast_win(NULLIF(s, 4), 123) over w
from (
  select s, s % 2 as p
  from generate_series(1,10) s
) foo
window w as (partition by p order by s rows between unbounded preceding and unbounded following)
order by s;