e0ae3f69eb
FossilOrigin-Name: 05080344dceafcfb670fbf01f7d69a1d713a54b6845f968a9cfe941fb53b13af
137 lines
3.0 KiB
Plaintext
137 lines
3.0 KiB
Plaintext
# 2019 June 8
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# May you do good and not evil.
|
|
# May you find forgiveness for yourself and forgive others.
|
|
# May you share freely, never taking more than you give.
|
|
#
|
|
#***********************************************************************
|
|
# This file implements regression tests for SQLite library.
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
set testprefix window9
|
|
|
|
ifcapable !windowfunc {
|
|
finish_test
|
|
return
|
|
}
|
|
|
|
do_execsql_test 1.0 {
|
|
CREATE TABLE fruits(
|
|
name TEXT COLLATE NOCASE,
|
|
color TEXT COLLATE NOCASE
|
|
);
|
|
}
|
|
|
|
do_execsql_test 1.1 {
|
|
INSERT INTO fruits (name, color) VALUES ('apple', 'RED');
|
|
INSERT INTO fruits (name, color) VALUES ('APPLE', 'yellow');
|
|
INSERT INTO fruits (name, color) VALUES ('pear', 'YELLOW');
|
|
INSERT INTO fruits (name, color) VALUES ('PEAR', 'green');
|
|
}
|
|
|
|
do_execsql_test 1.2 {
|
|
SELECT name, color, dense_rank() OVER (ORDER BY name) FROM fruits;
|
|
} {
|
|
apple RED 1
|
|
APPLE yellow 1
|
|
pear YELLOW 2
|
|
PEAR green 2
|
|
}
|
|
|
|
do_execsql_test 1.3 {
|
|
SELECT name, color,
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits;
|
|
} {
|
|
apple RED 1
|
|
APPLE yellow 2
|
|
PEAR green 1
|
|
pear YELLOW 2
|
|
}
|
|
|
|
do_execsql_test 1.4 {
|
|
SELECT name, color,
|
|
dense_rank() OVER (ORDER BY name),
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits;
|
|
} {
|
|
apple RED 1 1
|
|
APPLE yellow 1 2
|
|
PEAR green 2 1
|
|
pear YELLOW 2 2
|
|
}
|
|
|
|
do_execsql_test 1.5 {
|
|
SELECT name, color,
|
|
dense_rank() OVER (ORDER BY name),
|
|
dense_rank() OVER (PARTITION BY name ORDER BY color)
|
|
FROM fruits ORDER BY color;
|
|
} {
|
|
PEAR green 2 1
|
|
apple RED 1 1
|
|
APPLE yellow 1 2
|
|
pear YELLOW 2 2
|
|
}
|
|
|
|
do_execsql_test 2.0 {
|
|
CREATE TABLE t1(a BLOB, b INTEGER, c COLLATE nocase);
|
|
INSERT INTO t1 VALUES(1, 2, 'abc');
|
|
INSERT INTO t1 VALUES(3, 4, 'ABC');
|
|
}
|
|
|
|
do_execsql_test 2.1.1 {
|
|
SELECT c=='Abc' FROM t1
|
|
} {1 1}
|
|
do_execsql_test 2.1.2 {
|
|
SELECT c=='Abc', rank() OVER (ORDER BY b) FROM t1
|
|
} {1 1 1 2}
|
|
|
|
do_execsql_test 2.2.1 {
|
|
SELECT b=='2' FROM t1
|
|
} {1 0}
|
|
do_execsql_test 2.2.2 {
|
|
SELECT b=='2', rank() OVER (ORDER BY a) FROM t1
|
|
} {1 1 0 2}
|
|
|
|
#-------------------------------------------------------------------------
|
|
reset_db
|
|
do_execsql_test 3.0 {
|
|
CREATE TABLE t1(a);
|
|
CREATE TABLE t2(a,b,c);
|
|
}
|
|
|
|
do_execsql_test 3.1 {
|
|
SELECT EXISTS(SELECT 1 FROM t1 ORDER BY sum(a) OVER ()) FROM t1;
|
|
}
|
|
|
|
do_execsql_test 3.2 {
|
|
SELECT sum(a) OVER () FROM t2
|
|
ORDER BY EXISTS(SELECT 1 FROM t2 ORDER BY sum(a) OVER ());
|
|
}
|
|
|
|
do_catchsql_test 3.3 {
|
|
SELECT a, sum(a) OVER (ORDER BY a DESC) FROM t2
|
|
ORDER BY EXISTS(
|
|
SELECT 1 FROM t2 ORDER BY sum(a) OVER (ORDER BY a)
|
|
) OVER (ORDER BY a);
|
|
} {1 {near "OVER": syntax error}}
|
|
|
|
do_catchsql_test 3.4 {
|
|
SELECT y, y+1, y+2 FROM (
|
|
SELECT c IN (
|
|
SELECT min(a) OVER (),
|
|
(abs(row_number() OVER())+22)/19,
|
|
max(a) OVER () FROM t1
|
|
) AS y FROM t2
|
|
);
|
|
} {1 {sub-select returns 3 columns - expected 1}}
|
|
|
|
|
|
finish_test
|
|
|