If I execute the following in a file with the pgsql command, it complains that the procedure needs to be called with 'perform'. But when I try to use perform, it tells me that perform is not defined. What's the solution?
create or replace function waitris() returns void as
$$
declare
cnt integer;
begin
loop
select count(*) into cnt from taskflag where taskid = 'rdfdb' and state != 2;
if cnt = 0 then
exit;
end if;
select pg_sleep(1);
end loop;
end;
$$
language plpgsql;
select waitris();