I have a query which can return 0,1, or more rows.
This is my function:
CREATE OR REPLACE FUNCTION A(v_x integer[])
RETURNS void AS
$BODY$
declare
x_part integer;
x_part2 integer;
x_sum integer;

begin
select a,b,sum(qty) into x_part, x_part2,x_sum
from tablet
where location= any (v_x)
group by a,b


..... more actions....
end;
$BODY$
LANGUAGE plpgsql VOLATILE
I have two problems:

  1. if the query return more than one row I can not save the result into x_part,x_part2,x_sum.
  2. How can I tell the number of rows returned?

Basically what I need is if there is more than 1 row to get out of the function with error msg, if there is 1 or 0 rows.. keep going with the function operation.
How do I do that?


Check Solution