我想使用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
创建的查询失败。