How do I get the immediate children from a given path in an ltree
type in Postgres assuming the path always starts at root? For example if the given path is A.B
and the column name of ltree
is path
, then the best I could come up with is:
SELECT distinct(subpath(path, (SELECT distinct(nlevel('A.B'))), 1)) FROM test_ltree WHERE path ~ 'A.B.*{1,}';';
Edit: I only want to return the children, without the parents in the path.