I try to do recursive function in postgres.
As an argument to the fucntion I provide id
, then I need to query table to get detail information about it. One of columns parent_id
has a tree structure. Lowwer numer are higher in a tree structure. I would like to ahead higher results in my tree structure.
This is my sql query:
create or replace function provide_city_name(id_offer int)
returns int
language plpgsql
as
$$
declare
city_name varchar;
begin
select id, type, parent_id, name into city_name
from location
where id = id_offer;
if type < 6 then
return city_name;
else
return provide_city_name(parent_id);
end if;
end;
$$;
I got following message:
':=', <analytic clause>, '=', WITHIN or '[' expected, got ';'
. It occcured in lines with
else
provide_city_name(parent_id);
question from:
https://stackoverflow.com/questions/65952122/recursive-function-in-postgres-based-on-query-result 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…