0

Trying to display the result in the form of table with different columns, but getting all result in a single column.

--My Function

create or replace function test1()       
returns table ( "Fname" varchar(20),"Lname" varchar(20),"A-B" bigint,"C-D" bigint,
"E-F" bigint ) as    
$body$  
begin  
return query  
SELECT tb."Fname",tb."Lname",count(tb."City"='A-B' OR NULL) AS "A-B",  
   count(tb."City"='C-D' OR NULL) AS "C-D",  
   count(tb."City"='E-F' OR NULL) AS "E-F"  
FROM "Table1" tb    
WHERE  tb."City" in ('A-B','C-D','E-F')    
GROUP BY 1,2  
ORDER BY 1,2;    
end  
$body$  
language plpgsql;  

2 Answers 2

1

In instead of

select test1()

do

select * from test1()
Sign up to request clarification or add additional context in comments.

Comments

1

You need no plgpsql for this. This is just a plain query.

But supposing you just want to test it: How do you call the function?

For table returning functions you do: select * from f1();.

For functions returning one value you do select f1();.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.