3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. Specifically,
12 # it tests the sqlite3_create_window_function() API.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix window1
19 proc m_step {ctx val} {
24 set lSort [lsort $ctx]
26 set nVal [llength $lSort]
29 if {($nVal % 2)==0 && $nVal>0} {
30 set a [lindex $lSort $n]
31 set b [lindex $lSort $n-1]
33 set ret [expr ($a+$b)/2.0]
35 set ret [expr ($a+$b)/2]
38 set ret [lindex $lSort $n]
42 proc m_inverse {ctx val} {
43 set ctx [lrange $ctx 1 end]
50 sqlite3_create_window_function db median m_step m_value m_value m_inverse
51 sqlite3_create_window_function db win m_step w_value w_value m_inverse
54 CREATE TABLE t1(a, b);
55 INSERT INTO t1 VALUES(4, 'a');
56 INSERT INTO t1 VALUES(6, 'b');
57 INSERT INTO t1 VALUES(1, 'c');
58 INSERT INTO t1 VALUES(5, 'd');
59 INSERT INTO t1 VALUES(2, 'e');
60 INSERT INTO t1 VALUES(3, 'f');
64 SELECT win(a) OVER (ORDER BY b), median(a) OVER (ORDER BY b) FROM t1;
65 } {4 4 {4 6} 5 {1 4 6} 4 {1 4 5 6} 4.5 {1 2 4 5 6} 4 {1 2 3 4 5 6} 3.5}