postresql can do it in one statement, but it's ugly and non-recursive (you COULD write a function on plsql to do this recursively, but the sql in postgres doesn't do recursion natively.)
Here's one that works for two levels, I'll leave it to you to add the third possible level yourself:
select ida, idb from relation where idb in (select ida from relation where idb=4) union select ida, idb from relation where idb=4;