sql - connect_by_root equivalent in postgres -
how can covert connect_by_root query of oracle in postgres. ex: oracle query.
select fg_id, connect_by_root fg_id fg_classifier_id fg start parent_fg_id null connect prior fg_id = parent_fg_id
you use recursive common table expression "carries" root through recursion levels:
with recursive fg_tree ( select fg_id, fg_id fg_clasifier_id -- <<< "root" fg parent_fg_id null -- <<< "start with" part union select c.fg_id, p.fg_clasifier_id fg c join fg_tree p on p.fg_id = c.parent_fg_id -- <<< "connect by" part ) select * fg_tree;
more details on recursive common table expressions in manual: http://www.postgresql.org/docs/current/static/queries-with.html
Comments
Post a Comment