提交 8b34bde2 authored 作者: Thomas Mueller's avatar Thomas Mueller

A query with an explicit LIMIT 0 will now return no rows (so far it meant no…

A query with an explicit LIMIT 0 will now return no rows (so far it meant no limit), which is compatible with PostgreSQL and MySQL. A negative limit value (as well as LIMIT NULL) mean no limit (so far a negative limit meant a limit of one row).
上级 7a8584bc
......@@ -17,9 +17,9 @@ HAVING filter rows after grouping.
ORDER BY sorts the result by the given column(s) or expression(s).
UNION combines the result of this query with the results of another query.
LIMIT limits the number of rows returned by the query, OFFSET specified
how many rows to skip. SAMPLE_SIZE limits the number of rows read for
aggregate queries.
LIMIT limits the number of rows returned by the query (no limit if null or smaller than zero).
OFFSET specified how many rows to skip.
SAMPLE_SIZE limits the number of rows read for aggregate queries.
Multiple set operators (UNION, INTERSECT, MINUS, EXPECT) are evaluated
from left to right. For compatibility with other databases and future versions
......@@ -69,7 +69,7 @@ UPDATE PERSON P SET NAME=(SELECT A.NAME FROM ADDRESS A WHERE A.ID=P.ID);
DELETE [ TOP term ] FROM tableName [ WHERE expression ] [ LIMIT term ]
","
Deletes rows form a table.
If TOP or LIMIT is specified, at most the specified number of rows are deleted.
If TOP or LIMIT is specified, at most the specified number of rows are deleted (no limit if null or smaller than zero).
","
DELETE FROM TEST WHERE ID=2
"
......
......@@ -36,7 +36,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
private SortOrder sort;
private ValueHashMap<Value[]> distinctRows;
private Value[] currentRow;
private int offset, limit;
private int offset;
private int limit = -1;
private ResultExternal external;
private int diskOffset;
private boolean distinct;
......@@ -128,7 +129,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
copy.distinct = distinct;
copy.currentRow = null;
copy.offset = 0;
copy.limit = 0;
copy.limit = -1;
copy.external = e2;
copy.diskOffset = this.diskOffset;
return copy;
......@@ -317,14 +318,14 @@ public class LocalResult implements ResultInterface, ResultTarget {
/**
* Set the number of rows that this result will return at the maximum.
*
* @param limit the limit
* @param limit the limit (-1 means no limit, 0 means no rows)
*/
public void setLimit(int limit) {
this.limit = limit;
}
private void applyLimit() {
if (limit <= 0) {
if (limit < 0) {
return;
}
if (external == null) {
......
......@@ -35,6 +35,40 @@ create table test(id int);
insert into test values(1), (2), (4);
> update count: 3
select * from test order by id limit -1;
> ID
> --
> 1
> 2
> 4
> rows (ordered): 3
select * from test order by id limit 0;
> ID
> --
> rows (ordered): 0
select * from test order by id limit 1;
> ID
> --
> 1
> rows (ordered): 1
select * from test order by id limit 1+1;
> ID
> --
> 1
> 2
> rows (ordered): 2
select * from test order by id limit null;
> ID
> --
> 1
> 2
> 4
> rows (ordered): 3
select a.id, a.id in(select 4) x from test a, test b where a.id in (b.id, b.id - 1);
> ID X
> -- -----
......@@ -60,6 +94,15 @@ select a.id, 4 in(select a.id) x from test a, test b where a.id in (b.id, b.id
> 4 TRUE
> rows: 3
delete from test limit 0;
> ok
delete from test limit 1;
> update count: 1
delete from test limit -1;
> update count: 2
drop table test;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论