A more complete version of the SQL to be returned as TreeNode WITH RECURSIVE docorder AS ( select id, rn from ...), parents AS (SELECT tree.id AS id, tree.parent_id AS parent_id, tree.name AS name FROM tree WHERE tree.name = 'subnode4' UNION SELECT tree.id AS tree_id, tree.parent_id AS tree_parent_id, tree.name AS tree_name FROM tree, parents WHERE tree.id = parents.parent_id), kids AS (SELECT tree.id AS id, tree.parent_id AS parent_id, tree.name AS name FROM tree WHERE tree.name = 'subnode4' UNION SELECT tree.id AS tree_id, tree.parent_id AS tree_parent_id, tree.name AS tree_name FROM tree, kids WHERE tree.parent_id = kids.id) SELECT n.id, n.parent_id, n.name FROM ( SELECT parents.id, parents.parent_id, parents.name FROM parents UNION SELECT kids.id, kids.parent_id, kids.name FROM kids) AS n, docorder WHERE n.id = docorder.id ORDER BY docorder.rn, n.parent_id
-- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/ae4cfacb-ef3f-4d78-961d-45f8ee09f846n%40googlegroups.com.