1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add support for RANGE window frames. Some cases still do not work.

FossilOrigin-Name: ffc32b246d92d53c66094afe11950b53ffab6a1c230c602eebbfedafb2eb57f4
This commit is contained in:
dan
2019-03-09 20:49:17 +00:00
parent f7b846e4ed
commit 72b9fdcf20
9 changed files with 228 additions and 73 deletions

View File

@ -23,48 +23,60 @@ ifcapable !windowfunc { finish_test ; return }
do_execsql_test 1.0 {
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a INTEGER, b INTEGER);
INSERT INTO t1 VALUES(1, 1);
INSERT INTO t1 VALUES(2, 2);
INSERT INTO t1 VALUES(3, 3);
INSERT INTO t1 VALUES(4, 4);
INSERT INTO t1 VALUES(5, 5);
} {}
# PG says "ERROR: frame starting offset must not be negative"
# PG says ERROR: frame starting offset must not be negative
do_test 1.1 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a ROWS BETWEEN -1 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says "ERROR: frame ending offset must not be negative"
# PG says ERROR: frame ending offset must not be negative
do_test 1.2 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a ROWS BETWEEN 1 PRECEDING AND -1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says "ERROR: invalid preceding or following size in window function"
# PG says ERROR: invalid preceding or following size in window function
do_test 1.3 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN -1 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says "ERROR: invalid preceding or following size in window function"
# PG says ERROR: invalid preceding or following size in window function
do_test 1.4 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a RANGE BETWEEN 1 PRECEDING AND -1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says "ERROR: frame starting offset must not be negative"
# PG says ERROR: frame starting offset must not be negative
do_test 1.5 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a GROUPS BETWEEN -1 PRECEDING AND 1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says "ERROR: frame ending offset must not be negative"
# PG says ERROR: frame ending offset must not be negative
do_test 1.6 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a GROUPS BETWEEN 1 PRECEDING AND -1 FOLLOWING
) FROM t3 ORDER BY 1
) FROM t1 ORDER BY 1
} } } 1
# PG says ERROR: RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column
do_test 1.7 { catch { execsql {
SELECT a, sum(b) OVER (
ORDER BY a,b RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING
) FROM t1 ORDER BY 1
} } } 1
finish_test