PostgreSQL:如何使用PostgreSQL在函数中返回SELECT语句的结果?

时间:2014-03-10 07:37:15

标签: postgresql

这里我有以下功能,但没有得到如何返回结果。

create or replace function f1() returns void as  
$body$  
begin    
    SELECT "Fname",  
        "Lname",   
        count("City" = 'A-B' OR NULL) AS "A-B",  
        count("City" = 'C-D' OR NULL) AS "C-D",  
    FROM "Table1"  
    WHERE  "City" in ('A-B','C-D')  
    GROUP BY 1,2  
    ORDER BY 1,2  

1 个答案:

答案 0 :(得分:2)

将返回类型更改为RETURNS TABLE (fieldname type, fieldname type, ...)并使用RETURN QUERY SELECT ...

请参阅the PL/PgSQL docs