I have a question, what is missing or wrong in the RETURN statement that it keeps crashing error 2F005
I am creating a table to log errors
drop table if exists public.funkcja_x;
create table public.funkcja_x
(
error_alert text
);
I am creating function
drop function if exists public.test();
create or replace function public.test()
returns text as
$body$
declare
v_error text;
begin
-- i intentionally create a table from a table that doesn't exist to force an error
drop table if exists public.tabela_final;
create table public.tabela_final as
select * from public.tabela_posrednia;
return 'OK';
exception when others then
v_error := SQLERRM;
insert into public.funkcja_x (error_alert) values (v_error);
end;
$body$
language plpgsql volatile cost 100;
alter function public.test() owner to postgres;
evokes:
select public.test();
and gets error:
BŁĄD: osiągnięto koniec funkcji, brakuje instrukcji RETURN
Stan SQL: 2F005
Kontekst: funkcja PL/pgSQL test()
2
Answers
Hmmm I found a solution, you have to replace TEXT to VOID and then it works :) but thank you for your interest and sorry for the spam :)
You are missing
RETURN
statement. Any non void function in PL/pgSQL should to return data. Your function usesRETURNS text
but returns nothing. Probably missRETURN 'false'
.You can use
boolean
instead text as return type.