0

Here i have following function, but not getting how to return the result.

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
  • When you would to get some result from function, then your function MUST not be VOID function. Commented Mar 10, 2014 at 8:05

1 Answer 1

2

Change the return type to RETURNS TABLE (fieldname type, fieldname type, ...) and use RETURN QUERY SELECT ....

See the PL/PgSQL docs.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. But the result is showing in a single column.
@user3382347 Wild guess: You're using SELECT my_procedure() not SELECT * FROM my_procedure().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.