Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dfb7bba0
提交
dfb7bba0
authored
9月 27, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Detect ordered result sets properly
上级
3e2bf8da
全部展开
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
184 行增加
和
124 行删除
+184
-124
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+66
-6
select.sql
h2/src/test/org/h2/test/scripts/dml/select.sql
+27
-27
show.sql
h2/src/test/org/h2/test/scripts/dml/show.sql
+7
-7
array-agg.sql
...est/org/h2/test/scripts/functions/aggregate/array-agg.sql
+33
-33
count.sql
...rc/test/org/h2/test/scripts/functions/aggregate/count.sql
+2
-2
group-concat.sql
.../org/h2/test/scripts/functions/aggregate/group-concat.sql
+4
-4
sum.sql
h2/src/test/org/h2/test/scripts/functions/aggregate/sum.sql
+2
-2
lead.sql
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
+6
-6
nth_value.sql
...c/test/org/h2/test/scripts/functions/window/nth_value.sql
+6
-6
ntile.sql
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
+9
-9
row_number.sql
.../test/org/h2/test/scripts/functions/window/row_number.sql
+4
-4
testScript.sql
h2/src/test/org/h2/test/scripts/testScript.sql
+13
-13
window.sql
h2/src/test/org/h2/test/scripts/window.sql
+5
-5
没有找到文件。
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
dfb7bba0
...
...
@@ -27,8 +27,13 @@ import java.util.Map;
import
java.util.Random
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandContainer
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Query
;
import
org.h2.engine.SysProperties
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.jdbc.JdbcPreparedStatement
;
import
org.h2.test.TestAll
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
...
...
@@ -42,6 +47,12 @@ public class TestScript extends TestDb {
private
static
final
String
BASE_DIR
=
"org/h2/test/scripts/"
;
private
static
final
Field
COMMAND
;
private
static
final
Field
PREPARED
;
private
static
boolean
CHECK_ORDERING
;
/** If set to true, the test will exit at the first failure. */
private
boolean
failFast
;
/** If set to a value the test will add all executed statements to this list */
...
...
@@ -59,12 +70,24 @@ public class TestScript extends TestDb {
private
Random
random
=
new
Random
(
1
);
static
{
try
{
COMMAND
=
JdbcPreparedStatement
.
class
.
getDeclaredField
(
"command"
);
COMMAND
.
setAccessible
(
true
);
PREPARED
=
CommandContainer
.
class
.
getDeclaredField
(
"prepared"
);
PREPARED
.
setAccessible
(
true
);
}
catch
(
ReflectiveOperationException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
CHECK_ORDERING
=
true
;
TestBase
.
createCaller
().
init
().
test
();
}
...
...
@@ -421,10 +444,20 @@ public class TestScript extends TestDb {
private
int
processStatement
(
String
sql
)
throws
Exception
{
try
{
if
(
stat
.
execute
(
sql
))
{
writeResultSet
(
sql
,
stat
.
getResultSet
());
boolean
res
;
Statement
s
;
if
(
/* TestScript */
CHECK_ORDERING
||
/* TestAll */
config
.
memory
&&
!
config
.
lazy
&&
!
config
.
networked
)
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
sql
);
res
=
prep
.
execute
();
s
=
prep
;
}
else
{
res
=
stat
.
execute
(
sql
);
s
=
stat
;
}
if
(
res
)
{
writeResultSet
(
sql
,
s
.
getResultSet
());
}
else
{
int
count
=
s
tat
.
getUpdateCount
();
int
count
=
s
.
getUpdateCount
();
writeResult
(
sql
,
count
<
1
?
"ok"
:
"update count: "
+
count
,
null
);
}
}
catch
(
SQLException
e
)
{
...
...
@@ -474,6 +507,17 @@ public class TestScript extends TestDb {
}
head
[
i
]
=
label
;
}
Boolean
gotOrdered
=
null
;
Statement
st
=
rs
.
getStatement
();
if
(
st
instanceof
JdbcPreparedStatement
)
{
CommandInterface
ci
=
(
CommandInterface
)
COMMAND
.
get
(
st
);
if
(
ci
instanceof
CommandContainer
)
{
Prepared
p
=
(
Prepared
)
PREPARED
.
get
(
ci
);
if
(
p
instanceof
Query
)
{
gotOrdered
=
((
Query
)
p
).
hasOrder
();
}
}
}
rs
.
close
();
String
line
=
readLine
();
putBack
(
line
);
...
...
@@ -495,7 +539,7 @@ public class TestScript extends TestDb {
return
;
}
}
b
oolean
ordered
;
B
oolean
ordered
;
for
(;;)
{
line
=
readNextLine
();
if
(
line
==
null
)
{
...
...
@@ -509,6 +553,20 @@ public class TestScript extends TestDb {
}
else
if
(
line
.
startsWith
(
"> rows (ordered): "
))
{
ordered
=
true
;
break
;
}
else
if
(
line
.
startsWith
(
"> rows (partially ordered): "
))
{
ordered
=
null
;
break
;
}
}
if
(
gotOrdered
!=
null
&&
ordered
!=
null
)
{
if
(
ordered
)
{
if
(!
gotOrdered
)
{
addWriteResultError
(
"<ordered result set>"
,
"<result set>"
);
}
}
else
{
if
(
gotOrdered
)
{
addWriteResultError
(
"<result set>"
,
"<ordered result set>"
);
}
}
}
writeResult
(
sql
,
format
(
head
,
max
),
null
);
...
...
@@ -517,14 +575,16 @@ public class TestScript extends TestDb {
for
(
int
i
=
0
;
i
<
result
.
size
();
i
++)
{
array
[
i
]
=
format
(
result
.
get
(
i
),
max
);
}
if
(!
ordered
)
{
if
(!
Boolean
.
TRUE
.
equals
(
ordered
)
)
{
sort
(
array
);
}
int
i
=
0
;
for
(;
i
<
array
.
length
;
i
++)
{
writeResult
(
sql
,
array
[
i
],
null
);
}
writeResult
(
sql
,
(
ordered
?
"rows (ordered): "
:
"rows: "
)
+
i
,
null
);
writeResult
(
sql
,
(
ordered
!=
null
?
ordered
?
"rows (ordered): "
:
"rows: "
:
"rows (partially ordered): "
)
+
i
,
null
);
}
private
static
String
format
(
String
[]
row
,
int
[]
max
)
{
...
...
h2/src/test/org/h2/test/scripts/dml/select.sql
浏览文件 @
dfb7bba0
...
...
@@ -25,7 +25,7 @@ SELECT * FROM TEST ORDER BY A, B;
>
2
2
1
>
2
2
2
>
2
2
3
>
rows
(
ordered
):
12
>
rows
(
partially
ordered
):
12
SELECT
*
FROM
TEST
ORDER
BY
A
,
B
,
C
FETCH
FIRST
4
ROWS
ONLY
;
>
A
B
C
...
...
@@ -43,7 +43,7 @@ SELECT * FROM TEST ORDER BY A, B, C FETCH FIRST 4 ROWS WITH TIES;
>
1
1
2
>
1
1
3
>
1
2
1
>
rows
:
4
>
rows
(
ordered
)
:
4
SELECT
*
FROM
TEST
ORDER
BY
A
,
B
FETCH
FIRST
4
ROWS
WITH
TIES
;
>
A
B
C
...
...
@@ -54,7 +54,7 @@ SELECT * FROM TEST ORDER BY A, B FETCH FIRST 4 ROWS WITH TIES;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
6
>
rows
(
partially
ordered
)
:
6
SELECT
*
FROM
TEST
ORDER
BY
A
FETCH
FIRST
ROW
WITH
TIES
;
>
A
B
C
...
...
@@ -65,7 +65,7 @@ SELECT * FROM TEST ORDER BY A FETCH FIRST ROW WITH TIES;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
6
>
rows
(
partially
ordered
)
:
6
SELECT
TOP
(
1
)
WITH
TIES
*
FROM
TEST
ORDER
BY
A
;
>
A
B
C
...
...
@@ -76,7 +76,7 @@ SELECT TOP (1) WITH TIES * FROM TEST ORDER BY A;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
6
>
rows
(
partially
ordered
)
:
6
SELECT
TOP
1
PERCENT
WITH
TIES
*
FROM
TEST
ORDER
BY
A
;
>
A
B
C
...
...
@@ -87,7 +87,7 @@ SELECT TOP 1 PERCENT WITH TIES * FROM TEST ORDER BY A;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
6
>
rows
(
partially
ordered
)
:
6
SELECT
TOP
51
PERCENT
WITH
TIES
*
FROM
TEST
ORDER
BY
A
,
B
;
>
A
B
C
...
...
@@ -101,7 +101,7 @@ SELECT TOP 51 PERCENT WITH TIES * FROM TEST ORDER BY A, B;
>
2
1
1
>
2
1
2
>
2
1
3
>
rows
:
9
>
rows
(
partially
ordered
)
:
9
SELECT
*
FROM
TEST
ORDER
BY
A
,
B
OFFSET
3
ROWS
FETCH
NEXT
1
ROW
WITH
TIES
;
>
A
B
C
...
...
@@ -109,7 +109,7 @@ SELECT * FROM TEST ORDER BY A, B OFFSET 3 ROWS FETCH NEXT 1 ROW WITH TIES;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
3
>
rows
(
partially
ordered
)
:
3
SELECT
*
FROM
TEST
FETCH
NEXT
ROWS
ONLY
;
>
A
B
C
...
...
@@ -163,7 +163,7 @@ SELECT * FROM TEST ORDER BY A FETCH FIRST 1 ROW WITH TIES;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
6
>
rows
(
partially
ordered
)
:
6
SELECT
*
FROM
TEST
ORDER
BY
A
,
B
OFFSET
3
ROWS
FETCH
NEXT
1
ROW
WITH
TIES
;
>
A
B
C
...
...
@@ -171,7 +171,7 @@ SELECT * FROM TEST ORDER BY A, B OFFSET 3 ROWS FETCH NEXT 1 ROW WITH TIES;
>
1
2
1
>
1
2
2
>
1
2
3
>
rows
:
3
>
rows
(
partially
ordered
)
:
3
SELECT
*
FROM
TEST
FETCH
FIRST
1
ROW
WITH
TIES
;
>
exception
WITH_TIES_WITHOUT_ORDER_BY
...
...
@@ -183,7 +183,7 @@ SELECT * FROM TEST FETCH FIRST 1 ROW WITH TIES;
>
1
2
2
>
1
2
3
>
1
2
4
>
rows
:
4
>
rows
(
partially
ordered
)
:
4
(
SELECT
*
FROM
TEST
)
UNION
(
SELECT
1
,
2
,
4
)
ORDER
BY
A
,
B
OFFSET
3
ROWS
FETCH
NEXT
50
PERCENT
ROWS
ONLY
;
>
A
B
C
...
...
@@ -195,7 +195,7 @@ SELECT * FROM TEST FETCH FIRST 1 ROW WITH TIES;
>
2
1
1
>
2
1
2
>
2
1
3
>
rows
:
7
>
rows
(
partially
ordered
)
:
7
(
SELECT
*
FROM
TEST
)
UNION
(
SELECT
1
,
2
,
4
)
ORDER
BY
A
,
B
OFFSET
3
ROWS
FETCH
NEXT
40
PERCENT
ROWS
WITH
TIES
;
>
A
B
C
...
...
@@ -207,7 +207,7 @@ SELECT * FROM TEST FETCH FIRST 1 ROW WITH TIES;
>
2
1
1
>
2
1
2
>
2
1
3
>
rows
:
7
>
rows
(
partially
ordered
)
:
7
(
SELECT
*
FROM
TEST
)
UNION
(
SELECT
1
,
2
,
4
)
FETCH
NEXT
1
ROW
WITH
TIES
;
>
exception
WITH_TIES_WITHOUT_ORDER_BY
...
...
@@ -233,7 +233,7 @@ SELECT A, B FROM TEST ORDER BY A FETCH FIRST 1 ROW WITH TIES;
>
0
1
>
0
3
>
0
.
0
2
>
rows
:
3
>
rows
(
partially
ordered
)
:
3
DROP
TABLE
TEST
;
>
ok
...
...
h2/src/test/org/h2/test/scripts/dml/show.sql
浏览文件 @
dfb7bba0
...
...
@@ -60,35 +60,35 @@ SHOW TABLES;
>
TABLE_NAME
TABLE_SCHEMA
>
---------- ------------
>
TEST_P
PUBLIC
>
rows
:
1
>
rows
(
ordered
)
:
1
SHOW
TABLES
FROM
PUBLIC
;
>
TABLE_NAME
TABLE_SCHEMA
>
---------- ------------
>
TEST_P
PUBLIC
>
rows
:
1
>
rows
(
ordered
)
:
1
SHOW
TABLES
FROM
SCH
;
>
TABLE_NAME
TABLE_SCHEMA
>
---------- ------------
>
TEST_S
SCH
>
rows
:
1
>
rows
(
ordered
)
:
1
SHOW
COLUMNS
FROM
TEST_P
;
>
FIELD
TYPE
NULL
KEY
DEFAULT
>
----- ------------ ---- --- -------
>
ID_P
INTEGER
(
10
)
NO
PRI
NULL
>
N_P
INTEGER
(
10
)
YES
1
>
U_P
VARCHAR
(
255
)
YES
UNI
NULL
>
rows
:
3
>
N_P
INTEGER
(
10
)
YES
1
>
rows
(
ordered
):
3
SHOW
COLUMNS
FROM
TEST_S
FROM
SCH
;
>
FIELD
TYPE
NULL
KEY
DEFAULT
>
----- ------------ ---- --- -------
>
ID_S
INTEGER
(
10
)
NO
PRI
NULL
>
N_S
INTEGER
(
10
)
YES
1
>
U_S
VARCHAR
(
255
)
YES
UNI
NULL
>
rows
:
3
>
N_S
INTEGER
(
10
)
YES
1
>
rows
(
ordered
):
3
SHOW
DATABASES
;
>
SCHEMA_NAME
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/array-agg.sql
浏览文件 @
dfb7bba0
差异被折叠。
点击展开。
h2/src/test/org/h2/test/scripts/functions/aggregate/count.sql
浏览文件 @
dfb7bba0
...
...
@@ -60,7 +60,7 @@ SELECT COUNT(ID) OVER (ORDER BY NAME) AS NR,
>
-- --
>
1
3
>
2
1
>
rows
(
ordered
)
:
2
>
rows
:
2
SELECT
NR
FROM
(
SELECT
COUNT
(
ID
)
OVER
(
ORDER
BY
NAME
)
AS
NR
,
A
.
ID
AS
ID
FROM
(
SELECT
ID
,
NAME
FROM
TEST
ORDER
BY
NAME
)
AS
A
)
...
...
@@ -82,7 +82,7 @@ SELECT I, V, COUNT(V) OVER W C, COUNT(DISTINCT V) OVER W D FROM
>
5
2
5
2
>
6
2
6
2
>
7
3
7
3
>
rows
(
ordered
)
:
7
>
rows
:
7
SELECT
I
,
C
,
COUNT
(
I
)
OVER
(
PARTITION
BY
C
)
CNT
FROM
VALUES
(
1
,
1
),
(
2
,
1
),
(
3
,
2
),
(
4
,
2
),
(
5
,
2
)
T
(
I
,
C
);
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/group-concat.sql
浏览文件 @
dfb7bba0
...
...
@@ -17,7 +17,7 @@ select group_concat(v order by v asc separator '-'),
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
---------------------------------------- -----------------------------------------------------------------------
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
(
ordered
)
:
1
>
rows
:
1
create
index
test_idx
on
test
(
v
);
>
ok
...
...
@@ -28,7 +28,7 @@ select group_concat(v order by v asc separator '-'),
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
---------------------------------------- -----------------------------------------------------------------------
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
(
ordered
)
:
1
>
rows
:
1
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
...
...
@@ -36,7 +36,7 @@ select group_concat(v order by v asc separator '-'),
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
---------------------------------------- -----------------------------------------------------------------------
>
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
(
ordered
)
:
1
>
rows
:
1
drop
table
test
;
>
ok
...
...
@@ -63,7 +63,7 @@ select group_concat(distinct v order by v desc) from test;
>
GROUP_CONCAT
(
DISTINCT
V
ORDER
BY
V
DESC
)
>
----------------------------------------
>
9
,
8
,
7
,
3
,
2
,
-
1
>
rows
(
ordered
)
:
1
>
rows
:
1
drop
table
test
;
>
ok
h2/src/test/org/h2/test/scripts/functions/aggregate/sum.sql
浏览文件 @
dfb7bba0
...
...
@@ -80,7 +80,7 @@ SELECT
>
6
21
21
21
36
>
7
28
28
15
36
>
8
36
36
8
36
>
rows
(
ordered
)
:
8
>
rows
:
8
SELECT
I
,
V
,
SUM
(
V
)
OVER
W
S
,
SUM
(
DISTINCT
V
)
OVER
W
D
FROM
VALUES
(
1
,
1
),
(
2
,
1
),
(
3
,
1
),
(
4
,
1
),
(
5
,
2
),
(
6
,
2
),
(
7
,
3
)
T
(
I
,
V
)
...
...
@@ -94,4 +94,4 @@ SELECT I, V, SUM(V) OVER W S, SUM(DISTINCT V) OVER W D FROM
>
5
2
6
3
>
6
2
8
3
>
7
3
11
6
>
rows
(
ordered
)
:
7
>
rows
:
7
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
浏览文件 @
dfb7bba0
...
...
@@ -37,7 +37,7 @@ SELECT *,
>
7
22
33
33
33
21
21
21
>
8
33
null
null
null
22
22
22
>
9
null
null
null
null
33
33
33
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
LEAD
(
VALUE
,
1
)
OVER
(
ORDER
BY
ID
)
LD
,
...
...
@@ -58,7 +58,7 @@ SELECT *,
>
7
22
33
33
33
21
21
21
>
8
33
null
null
null
22
22
22
>
9
null
null
null
null
33
33
33
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
LEAD
(
VALUE
,
0
)
OVER
(
ORDER
BY
ID
)
LD
,
...
...
@@ -79,7 +79,7 @@ SELECT *,
>
7
22
22
22
22
22
22
22
>
8
33
33
33
33
33
33
33
>
9
null
null
null
null
null
null
null
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
LEAD
(
VALUE
,
2
)
OVER
(
ORDER
BY
ID
)
LD
,
...
...
@@ -100,7 +100,7 @@ SELECT *,
>
7
22
null
null
null
null
null
13
>
8
33
null
null
null
21
21
21
>
9
null
null
null
null
22
22
22
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
LEAD
(
VALUE
,
2
,
1111
.
0
)
OVER
(
ORDER
BY
ID
)
LD
,
...
...
@@ -121,7 +121,7 @@ SELECT *,
>
7
22
null
null
1111
null
null
13
>
8
33
1111
1111
1111
21
21
21
>
9
null
1111
1111
1111
22
22
22
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
LEAD
(
VALUE
,
-
1
)
OVER
(
ORDER
BY
ID
)
FROM
TEST
;
>
exception
INVALID_VALUE_2
...
...
@@ -144,7 +144,7 @@ SELECT LAG(VALUE) OVER (ORDER BY ID RANGE CURRENT ROW) FROM TEST;
DROP
TABLE
TEST
;
>
ok
SELECT
C
,
SUM
(
I
)
S
,
LEAD
(
SUM
(
I
))
OVER
(
ORDER
/**/
BY
SUM
(
I
))
L
FROM
SELECT
C
,
SUM
(
I
)
S
,
LEAD
(
SUM
(
I
))
OVER
(
ORDER
BY
SUM
(
I
))
L
FROM
VALUES
(
1
,
1
),
(
2
,
1
),
(
4
,
2
),
(
8
,
2
)
T
(
I
,
C
)
GROUP
BY
C
;
>
C
S
L
>
-
-- ----
...
...
h2/src/test/org/h2/test/scripts/functions/window/nth_value.sql
浏览文件 @
dfb7bba0
...
...
@@ -44,7 +44,7 @@ SELECT *,
>
4
1
13
null
null
12
13
13
13
>
5
1
null
null
null
12
null
null
13
>
6
1
13
null
null
12
13
13
13
>
rows
(
ordered
)
:
6
>
rows
:
6
SELECT
*
,
FIRST_VALUE
(
VALUE
)
OVER
(
ORDER
BY
ID
)
FIRST
,
...
...
@@ -59,7 +59,7 @@ SELECT *,
>
2
1
12
12
12
12
12
12
12
>
3
1
null
12
12
12
null
null
12
>
4
1
13
12
12
12
13
13
13
>
rows
(
ordered
)
:
3
>
rows
:
3
SELECT
*
,
NTH_VALUE
(
VALUE
,
2
)
OVER
(
ORDER
BY
ID
)
NTH
,
...
...
@@ -80,7 +80,7 @@ SELECT *,
>
4
1
13
12
12
null
12
12
null
13
13
12
>
5
1
null
12
12
13
12
12
13
13
13
12
>
6
1
13
12
12
null
12
12
null
13
13
13
>
rows
(
ordered
)
:
6
>
rows
:
6
SELECT
*
,
NTH_VALUE
(
VALUE
,
2
)
OVER
(
ORDER
BY
ID
)
F
,
...
...
@@ -92,7 +92,7 @@ SELECT *,
NTH_VALUE
(
VALUE
,
2
)
FROM
LAST
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
CURRENT
ROW
)
L_U_C
,
NTH_VALUE
(
VALUE
,
2
)
FROM
LAST
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
CURRENT
ROW
AND
UNBOUNDED
FOLLOWING
)
L_C_U
,
NTH_VALUE
(
VALUE
,
2
)
FROM
LAST
OVER
(
ORDER
BY
ID
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
)
L_U_U
FROM
TEST
;
FROM
TEST
ORDER
BY
ID
;
>
ID
CATEGORY
VALUE
F
F_U_C
F_C_U
F_U_U
L
L_U_C
L_C_U
L_U_U
>
-- -------- ----- ---- ----- ----- ----- ---- ----- ----- -----
>
1
1
null
null
null
12
12
null
null
41
41
...
...
@@ -117,7 +117,7 @@ SELECT *,
FIRST_VALUE
(
VALUE
)
OVER
(
PARTITION
BY
CATEGORY
ORDER
BY
ID
)
FIRST
,
LAST_VALUE
(
VALUE
)
OVER
(
PARTITION
BY
CATEGORY
ORDER
BY
ID
)
LAST
,
NTH_VALUE
(
VALUE
,
2
)
OVER
(
PARTITION
BY
CATEGORY
ORDER
BY
ID
)
NTH
FROM
TEST
;
FROM
TEST
ORDER
BY
ID
;
>
ID
CATEGORY
VALUE
FIRST
LAST
NTH
>
-- -------- ----- ----- ---- ----
>
1
1
null
null
null
null
...
...
@@ -144,7 +144,7 @@ SELECT ID, CATEGORY,
>
1
1
null
null
>
2
1
1
null
>
3
1
1
1
>
rows
(
ordered
)
:
3
>
rows
:
3
DROP
TABLE
TEST
;
>
ok
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
浏览文件 @
dfb7bba0
...
...
@@ -17,16 +17,16 @@ SELECT NTILE(1) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 2));
>
--------------------------
>
1
>
1
>
rows
(
ordered
)
:
2
>
rows
:
2
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
2
));
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
2
))
ORDER
BY
X
;
>
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
>
2
>
rows
(
ordered
):
2
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
3
));
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
3
))
ORDER
BY
X
;
>
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
...
...
@@ -34,7 +34,7 @@ SELECT NTILE(2) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 3));
>
2
>
rows
(
ordered
):
3
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
4
));
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
4
))
ORDER
BY
X
;
>
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
...
...
@@ -43,7 +43,7 @@ SELECT NTILE(2) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 4));
>
2
>
rows
(
ordered
):
4
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
5
));
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
5
))
ORDER
BY
X
;
>
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
...
...
@@ -53,7 +53,7 @@ SELECT NTILE(2) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 5));
>
2
>
rows
(
ordered
):
5
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
6
));
SELECT
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
6
))
ORDER
BY
X
;
>
NTILE
(
2
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
...
...
@@ -64,7 +64,7 @@ SELECT NTILE(2) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 6));
>
2
>
rows
(
ordered
):
6
SELECT
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
3
));
SELECT
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
3
))
ORDER
BY
X
;
>
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
>
---------------------------
>
1
...
...
@@ -72,7 +72,7 @@ SELECT NTILE(10) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 3));
>
3
>
rows
(
ordered
):
3
SELECT
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
22
));
SELECT
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
22
))
ORDER
BY
X
;
>
NTILE
(
10
)
OVER
(
ORDER
BY
X
)
>
---------------------------
>
1
...
...
@@ -102,7 +102,7 @@ SELECT NTILE(10) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 22));
SELECT
NTILE
(
0
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
>
exception
INVALID_VALUE_2
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
6
));
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
6
))
ORDER
BY
X
;
>
NTILE
(
X
)
OVER
(
ORDER
BY
X
)
>
--------------------------
>
1
...
...
h2/src/test/org/h2/test/scripts/functions/window/row_number.sql
浏览文件 @
dfb7bba0
...
...
@@ -41,7 +41,7 @@ SELECT *,
>
7
3
32
7
0
.
0
1
.
0
7
7
7
0
.
75
0
.
78
>
8
3
33
8
0
.
0
1
.
0
8
8
8
0
.
88
0
.
89
>
9
4
41
9
0
.
0
1
.
0
9
9
9
1
.
0
1
.
0
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
RN
,
...
...
@@ -61,7 +61,7 @@ SELECT *,
>
7
3
32
7
6
3
0
.
63
0
.
89
>
8
3
33
8
6
3
0
.
63
0
.
89
>
9
4
41
9
9
4
1
.
0
1
.
0
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
*
,
ROW_NUMBER
()
OVER
(
PARTITION
BY
CATEGORY
ORDER
BY
ID
)
RN
,
...
...
@@ -81,7 +81,7 @@ SELECT *,
>
7
3
32
2
2
2
0
.
5
0
.
67
>
8
3
33
3
3
3
1
.
0
1
.
0
>
9
4
41
1
1
1
0
.
0
1
.
0
>
rows
(
ordered
)
:
9
>
rows
:
9
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
RN
,
...
...
@@ -133,7 +133,7 @@ INSERT INTO TEST VALUES
(
4
,
'b'
,
8
);
>
update
count
:
4
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
TYPE
)
RN
,
TYPE
,
SUM
(
CNT
)
SUM
FROM
TEST
GROUP
BY
TYPE
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
TYPE
)
RN
,
TYPE
,
SUM
(
CNT
)
SUM
FROM
TEST
GROUP
BY
TYPE
;
>
RN
TYPE
SUM
>
-- ---- ---
>
1
a
1
...
...
h2/src/test/org/h2/test/scripts/testScript.sql
浏览文件 @
dfb7bba0
...
...
@@ -10,7 +10,7 @@ select * from test where id in (select id from test order by 'x');
>
ID
>
--
>
1
>
rows
(
ordered
)
:
1
>
rows
:
1
drop
table
test
;
>
ok
...
...
@@ -63,7 +63,7 @@ AND studentID = 2;
>
SUM
(
POINTS
)
>
-----------
>
30
>
rows
(
ordered
)
:
1
>
rows
:
1
SELECT
eventID
X
FROM
RESULTS
WHERE
studentID
=
2
...
...
@@ -85,7 +85,7 @@ AND studentID = 2;
>
SUM
(
R
.
POINTS
)
>
-------------
>
30
>
rows
(
ordered
)
:
1
>
rows
:
1
drop
table
results
;
>
ok
...
...
@@ -97,7 +97,7 @@ create table test(id int, name varchar) as select 1, 'a';
>
ID
>
--
>
1
>
rows
(
ordered
)
:
1
>
rows
:
1
drop
table
test
;
>
ok
...
...
@@ -162,7 +162,7 @@ select id from test where name in(null, null);
select
*
from
(
select
*
from
test
order
by
name
limit
1
)
where
id
<
10
;
>
ID
NAME
>
-- ----
>
rows
(
ordered
)
:
0
>
rows
:
0
drop
table
test
;
>
ok
...
...
@@ -335,7 +335,7 @@ select * from dual where x in (select x from dual group by x order by max(x));
>
X
>
-
>
1
>
rows
(
ordered
)
:
1
>
rows
:
1
create
table
test
(
d
decimal
(
1
,
2
));
>
exception
INVALID_VALUE_SCALE_PRECISION
...
...
@@ -742,7 +742,7 @@ select * from(select 1 from system_range(1, 2) group by sin(x) order by sin(x));
>
-
>
1
>
1
>
rows
(
ordered
)
:
2
>
rows
:
2
create
table
parent
as
select
1
id
,
2
x
;
>
ok
...
...
@@ -1190,7 +1190,7 @@ drop table p;
>
X
>
-
>
1
>
rows
(
ordered
)
:
1
>
rows
:
1
create
table
test
(
a
int
,
b
int
default
1
);
>
ok
...
...
@@ -2813,7 +2813,7 @@ select rownum, * from (select * from test where id>1 order by id desc);
> -------- -- ----
> 1 3 33
> 2 2 22
> rows
(ordered)
: 2
> rows: 2
update test set name='
x
' where rownum<2;
> update count: 1
...
...
@@ -3289,7 +3289,7 @@ select select a from test order by id;
> SELECT A FROM PUBLIC.TEST /* PUBLIC.PRIMARY_KEY_2 */ /* scanCount: 2 */ ORDER BY =ID /* index sorted */
> -------------------------------------------------------------------------------------------------------
> TRUE
> rows
(ordered)
: 1
> rows: 1
insert into test values(2, '
N
');
> update count: 1
...
...
@@ -6676,7 +6676,7 @@ SELECT GROUP_CONCAT(ID ORDER BY ID) FROM TEST;
>
GROUP_CONCAT
(
ID
ORDER
BY
ID
)
>
----------------------------
>
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
>
rows
(
ordered
)
:
1
>
rows
:
1
SELECT
STRING_AGG
(
ID
,
';'
)
FROM
TEST
;
>
GROUP_CONCAT
(
ID
SEPARATOR
';'
)
...
...
@@ -7945,9 +7945,9 @@ insert into test values (2014, 'execution'), (2015, 'execution'), (2016, 'execut
select
*
from
test
where
year
in
(
select
distinct
year
from
test
order
by
year
desc
limit
1
offset
0
);
>
YEAR
ACTION
>
---- ---------
>
2016
order
>
2016
execution
>
rows
(
ordered
):
2
>
2016
order
>
rows
:
2
drop
table
test
;
>
ok
...
...
h2/src/test/org/h2/test/scripts/window.sql
浏览文件 @
dfb7bba0
...
...
@@ -27,7 +27,7 @@ SELECT *, ROW_NUMBER() OVER W1, ROW_NUMBER() OVER W2 FROM TEST
>
2
3
1
2
1
>
3
2
2
1
2
>
4
1
2
2
1
>
rows
(
ordered
)
:
4
>
rows
:
4
SELECT
*
,
LAST_VALUE
(
ID
)
OVER
W
FROM
TEST
WINDOW
W
AS
(
PARTITION
BY
CATEGORY
ORDER
BY
ID
RANGE
BETWEEN
UNBOUNDED
PRECEDING
AND
UNBOUNDED
FOLLOWING
EXCLUDE
CURRENT
ROW
);
...
...
@@ -37,7 +37,7 @@ SELECT *, LAST_VALUE(ID) OVER W FROM TEST
>
2
3
1
1
>
3
2
2
4
>
4
1
2
3
>
rows
(
ordered
)
:
4
>
rows
:
4
DROP
TABLE
TEST
;
>
ok
...
...
@@ -75,7 +75,7 @@ SELECT ROW_NUMBER() OVER (ORDER /**/ BY CATEGORY), SUM(ID) FROM TEST GROUP BY C
>
1
12
>
rows
:
1
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
>
1
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
>
1
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
...
...
@@ -97,13 +97,13 @@ INSERT INTO TEST VALUES
(
32
,
FALSE
);
>
update
count
:
6
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
SUM
(
ID
)
=
12
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
SUM
(
ID
)
=
12
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
>
rows
:
1
SELECT
ROW_NUMBER
()
OVER
(
ORDER
/**/
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
;
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
),
SUM
(
ID
)
FROM
TEST
GROUP
BY
CATEGORY
HAVING
CATEGORY
;
>
ROW_NUMBER
()
OVER
(
ORDER
BY
CATEGORY
)
SUM
(
ID
)
>
------------------------------------- -------
>
1
12
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论