recursion - Recursive query in PostgreSQL. SELECT * -
i have recursive query retrieve children of given person
with recursive recursetree(id, parent_id) ( select id, parent_id tree parent_id = 0 union select t.id, t.parent_id tree t join recursetree rt on rt.id = t.parent_id ) select * recursetree;
as can see, i'm specifying list of columns retrieved. want use select *
(i have many columns in real table, , can changed in future). there way columns without defining each column individually?
you don't need specify columns in with
part. if leave out, column names determined first query in union
:
with recursive recursetree ( select * tree parent_id = 0 union select t.* tree t join recursetree rt on rt.id = t.parent_id ) select * recursetree;
Comments
Post a Comment