我正在尝试将group_concat函数添加到hsqldb中,以便可以将查询作为单元/集成测试进行正确测试。这个查询在mysql中工作得很好,所以我需要它在hsqldb中工作(希望如此)。
// GROUP_CONCAT
jdbcTemplate.update("DROP FUNCTION GROUP_CONCAT IF EXISTS;");
jdbcTemplate.update(
"create aggregate function group_concat(in val varchar(100), in flag boolean, inout buffer varchar(1000), inout counter int) " +
" returns varchar(1000) " +
" contains sql " +
"begin atomic " +
" if flag then" +
" return buffer;" +
" else" +
" if val is null then return null; end if;" +
" if buffer is null then set buffer = ''; end if;" +
" if counter is null then set counter = 0; end if;" +
" if counter > 0 then set buffer = buffer || ','; end if;" +
" set buffer = buffer + val;" +
" set counter = counter + 1;" +
" return null;" +
" end if;" +
"end;"
);添加这个聚合函数可以解决大部分问题。它将正确地表现为mysql的group_concat。但是,它不会让我像这样使用distinct关键字:
group_concat(distinct column)有什么方法可以考虑distinct关键字吗?或者重写查询以完全避免distinct关键字?
发布于 2012-10-19 05:14:24
HSQLDB有内置的GROUP_CONCAT并接受DISTINCT。
http://hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_aggregate_funcs
目前,您不能将DISTINCT添加到用户定义的聚合函数中,但这看起来是一个有趣的特性,可以在将来允许。
https://stackoverflow.com/questions/12963700
复制相似问题