Вам необходимо удалить declare
из begin/end
блока:
create or replace function foo() returns int as $$
declare fff int;
begin
-- declare fff int;
select count(*) into fff from mytable;
return fff;
end
$$ language plpgsql
дб <> скрипка
Ах. Правильно. Так вы не можете объявить переменную внутри блока BEGIN ... END?
Вы объявляете переменные на declare
части. Если вам нужно, вы можете вкладывать блоки:
create or replace function foo() returns int as $$
declare fff int;
begin
declare xxx INT;
begin
select count(*) into xxx from mytable;
return xxx;
end;
end
$$ language plpgsql