Skip to content

Commit

Permalink
Simplify SQL Server limit function
Browse files Browse the repository at this point in the history
Remove editing of the query, by putting the original query in a
subquery.
  • Loading branch information
findepi committed Jan 22, 2021
1 parent 4abdb48 commit bb7ef11
Showing 1 changed file with 1 addition and 6 deletions.
Expand Up @@ -65,7 +65,6 @@
import java.util.Optional;
import java.util.function.BiFunction;

import static com.google.common.base.Preconditions.checkArgument;
import static com.microsoft.sqlserver.jdbc.SQLServerConnection.TRANSACTION_SNAPSHOT;
import static io.airlift.slice.Slices.wrappedBuffer;
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
Expand Down Expand Up @@ -334,11 +333,7 @@ private static Optional<JdbcTypeHandle> toTypeHandle(DecimalType decimalType)
@Override
protected Optional<BiFunction<String, Long, String>> limitFunction()
{
return Optional.of((sql, limit) -> {
String start = "SELECT ";
checkArgument(sql.startsWith(start));
return "SELECT TOP " + limit + " " + sql.substring(start.length());
});
return Optional.of((sql, limit) -> format("SELECT TOP %s * FROM (%s) o", limit, sql));
}

@Override
Expand Down

0 comments on commit bb7ef11

Please sign in to comment.