xref: /sqlite-3.40.0/test/windowerr.test (revision 72b9fdcf)
1# 2019 March 01
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13
14####################################################
15# DO NOT EDIT! THIS FILE IS AUTOMATICALLY GENERATED!
16####################################################
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20set testprefix windowerr
21
22ifcapable !windowfunc { finish_test ; return }
23do_execsql_test 1.0 {
24  DROP TABLE IF EXISTS t1;
25  CREATE TABLE t1(a INTEGER, b INTEGER);
26  INSERT INTO t1 VALUES(1, 1);
27  INSERT INTO t1 VALUES(2, 2);
28  INSERT INTO t1 VALUES(3, 3);
29  INSERT INTO t1 VALUES(4, 4);
30  INSERT INTO t1 VALUES(5, 5);
31} {}
32
33# PG says ERROR:  frame starting offset must not be negative
34do_test 1.1 { catch { execsql {
35  SELECT a, sum(b) OVER (
36    ORDER BY a ROWS BETWEEN -1 PRECEDING AND 1 FOLLOWING
37  ) FROM t1 ORDER BY 1
38} } } 1
39
40# PG says ERROR:  frame ending offset must not be negative
41do_test 1.2 { catch { execsql {
42  SELECT a, sum(b) OVER (
43    ORDER BY a ROWS BETWEEN  1 PRECEDING AND -1 FOLLOWING
44  ) FROM t1 ORDER BY 1
45} } } 1
46
47# PG says ERROR:  invalid preceding or following size in window function
48do_test 1.3 { catch { execsql {
49  SELECT a, sum(b) OVER (
50    ORDER BY a RANGE BETWEEN -1 PRECEDING AND 1 FOLLOWING
51  ) FROM t1 ORDER BY 1
52} } } 1
53
54# PG says ERROR:  invalid preceding or following size in window function
55do_test 1.4 { catch { execsql {
56  SELECT a, sum(b) OVER (
57    ORDER BY a RANGE BETWEEN  1 PRECEDING AND -1 FOLLOWING
58  ) FROM t1 ORDER BY 1
59} } } 1
60
61# PG says ERROR:  frame starting offset must not be negative
62do_test 1.5 { catch { execsql {
63  SELECT a, sum(b) OVER (
64    ORDER BY a GROUPS BETWEEN -1 PRECEDING AND 1 FOLLOWING
65  ) FROM t1 ORDER BY 1
66} } } 1
67
68# PG says ERROR:  frame ending offset must not be negative
69do_test 1.6 { catch { execsql {
70  SELECT a, sum(b) OVER (
71    ORDER BY a GROUPS BETWEEN  1 PRECEDING AND -1 FOLLOWING
72  ) FROM t1 ORDER BY 1
73} } } 1
74
75# PG says ERROR:  RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column
76do_test 1.7 { catch { execsql {
77  SELECT a, sum(b) OVER (
78    ORDER BY a,b RANGE BETWEEN  1 PRECEDING AND 1 FOLLOWING
79  ) FROM t1 ORDER BY 1
80} } } 1
81
82finish_test
83