函数返回单个列中的数据,而不是3个单独的列

时间:2017-02-11 05:03:18

标签: sql postgresql

我的功能如下:

CREATE FUNCTION public.my_func(...)
  RETURNS TABLE(a integer, b timestamp without time zone, c timestamp without time zone) AS
$BODY$
BEGIN
    create temporary table t1 as
    select ....

RETURN QUERY
WITH RECURSIVE x AS ( working with t1 ..... ) SELECT x.a, x.b, x.c where ....;

当我将其称为“select my_func(1,2,3)”时,它会在一列中返回数据:

result
-----------
(32, "7-dec-2016", "3-mar-2017")

我希望它在3个单独的列中返回它。怎么样?

1 个答案:

答案 0 :(得分:2)

当您调用函数Map<Integer,String> tempMap = new TreeMap<Integer,String>(); Map<String,int []> resultMap = new LinkedHashMap<String,int[]>(); 时,您的结果将作为一个字段中的记录。你需要运行:

hm.entrySet().stream().sorted(Map.Entry.comparingByValue(
    new Comparator<int []>() {
    public int compare(int [] a,int [] b) {
        int sumA = a[0] + a[1];
        int sumB = b[0] + b[1];
        return sumA - sumB;
    }
}));