提交 5da46ca4 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Allow unrestricted ORDER BY with DISTINCT only in MySQL mode

上级 0690ef9a
......@@ -12,6 +12,7 @@ import org.h2.api.ErrorCode;
import org.h2.command.Prepared;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.Mode.ModeEnum;
import org.h2.expression.Alias;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn;
......@@ -478,8 +479,9 @@ public abstract class Query extends Prepared {
}
if (!isAlias) {
if (mustBeInResult) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT,
e.getSQL());
if (session.getDatabase().getMode().getEnum() != ModeEnum.MySQL) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
}
}
expressions.add(e);
String sql = e.getSQL();
......
......@@ -835,7 +835,7 @@ public class Select extends Query {
}
if (orderList != null) {
initOrder(session, expressions, expressionSQL, orderList,
visibleColumnCount, false, filters);
visibleColumnCount, distinct, filters);
}
distinctColumnCount = expressions.size();
if (having != null) {
......
......@@ -15,6 +15,9 @@ CREATE TABLE TEST2(ID2 BIGINT);
INSERT INTO TEST2 VALUES (1), (2);
> update count: 2
SET MODE MySQL;
> ok
SELECT DISTINCT ID FROM TEST ORDER BY NAME;
> ID
> --
......@@ -38,6 +41,9 @@ SELECT DISTINCT ID FROM TEST JOIN TEST2 ON ID = ID2 ORDER BY LOWER(NAME);
> 2
> rows (ordered): 2
SET MODE Regular;
> ok
DROP TABLE TEST;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论