提交 03a337de authored 作者: Thomas Mueller's avatar Thomas Mueller

Union queries: duplicate rows could be returned if the sub-queries contained "order by".

上级 e9e955f8
...@@ -18,7 +18,8 @@ Change Log ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The GEOMETRY data type now works for user defined functions that return a result set. <ul><li>Union queries: duplicate rows could be returned if the sub-queries contained "order by".
</li><li>The GEOMETRY data type now works for user defined functions that return a result set.
</li><li>PostgreSQL compatibility: the PgServer was not working properly when the setting </li><li>PostgreSQL compatibility: the PgServer was not working properly when the setting
database_to_upper was set to false. database_to_upper was set to false.
</li><li>JdbcDataSource: the methods setUrl and getUrl where added as aliases for setURL and getURL. </li><li>JdbcDataSource: the methods setUrl and getUrl where added as aliases for setURL and getURL.
......
...@@ -103,11 +103,20 @@ public class SelectUnion extends Query { ...@@ -103,11 +103,20 @@ public class SelectUnion extends Query {
} }
private Value[] convert(Value[] values, int columnCount) { private Value[] convert(Value[] values, int columnCount) {
Value[] newValues;
if (columnCount == values.length) {
// re-use the array if possible
newValues = values;
} else {
// create a new array if needed,
// for the value hash set
newValues = new Value[columnCount];
}
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
Expression e = expressions.get(i); Expression e = expressions.get(i);
values[i] = values[i].convertTo(e.getType()); newValues[i] = values[i].convertTo(e.getType());
} }
return values; return newValues;
} }
@Override @Override
......
...@@ -4,6 +4,18 @@ ...@@ -4,6 +4,18 @@
-- Initial Developer: H2 Group -- Initial Developer: H2 Group
-- --
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int, name varchar) as select 1, 'a';
> ok
(select id from test order by id) union (select id from test order by name);
> ID
> --
> 1
> rows (ordered): 1
drop table test;
> ok
create sequence seq; create sequence seq;
> ok > ok
...@@ -1334,8 +1346,7 @@ drop table p; ...@@ -1334,8 +1346,7 @@ drop table p;
> X > X
> - > -
> 1 > 1
> 1 > rows (ordered): 1
> rows (ordered): 2
create table test(a int, b int default 1); create table test(a int, b int default 1);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论