如何使用多个sortKeys创建PagingQueryProvider?

时间:2014-09-17 16:21:23

标签: java sql spring postgresql spring-batch

我想使用distinct on创建PagingQueryProvider查询:

    PostgresPagingQueryProvider queryProvider = new PostgresPagingQueryProvider();
    queryProvider.setSelectClause("DISTINCT ON (first, second) *");
    queryProvider.setFromClause("mytable");
    Map<String, Order> sortKeys = new HashMap<>();
    sortKeys.put("first", Order.ASCENDING);
    sortKeys.put("second", Order.ASCENDING);
    sortKeys.put("third", Order.ASCENDING);
    queryProvider.setSortKeys(sortKeys);

从提供者生成的结果sql:

SELECT DISTINCT ON(first, second) * FROM mytable ORDER BY first ASC, second ASC, third ASC;

错误:

ORDER BY items must appear in the select list if SELECT DISTINCT is specified

如果按如下方式生成此查询将是正确的:

SELECT DISTINCT ON(first, second) * FROM mytable ORDER BY first, second, third ASC;

但不是:我怎样才能在这里找到正确的区别? 奇怪的是:当在pgAdmin中针对数据库运行最后一个查询时,一切正常。 BUt由PagingQueryProvider创建的查询失败。

0 个答案:

没有答案