Answer the question
In order to leave comments, you need to log in
How to write a recursive function in PostgreSQL?
How to write a recursive function?
The function input is the movie id and the result is all the prequels for the movie.
create or replace function get_all_prequils(filmid int)
returns table (id int, filmname varchar, prequelid int) as $$
with recursive rec as (
select f.FilmID, f.FilmName, f.PrequelID
from Film as f
where f.FilmID = filmid
union
select r.FilmID, r.FilmName, r.PrequelID
from rec as r
join Film f on f.PrequelID = r.FilmID
)
select *
from rec
$$ language sql;
select get_all_prequils(1);
Answer the question
In order to leave comments, you need to log in
(?<!^)(\p{Lu})/gum
replace with " $1"
(space at the beginning)
https://regex101.com/r/nM45ZQ/1
Demo: https://ideone.com/cSH2eU
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question