you'd need to look into recursive querying. PG can do this with CTEs:
http://www.postgresql.org/docs/8.4/static/queries-with.html
here's a tutorial that IMO goes way too fast and complicated, but SQLA
can do the SELECT part of this at least:
http://schinckel.net/2014/11/27/postgres-tree-shootout-part-2%3A-adjacency-list-using-ctes/
On 6/9/15 2:13 PM, Ofir Herzas wrote:
I have a self referencing table like the following:
|
classEmployee(Base):
__tablename__ ="t_employee"
id
=sa.Column(BigInteger,sa.Sequence('%s_id_seq'%__tablename__),primary_key=True,nullable=False)
manager_id
=sa.Column(BigInteger,sa.ForeignKey("t_employee.id",ondelete='SET NULL'))
|
I want to select all rows ordered by their dependency (much like
metadata.sorted_tables does for tables). E.g - each manager should
come before his employees
What is the best way to achieve this (assuming the blunt
load-it-all-and-order-it is not the best method)?
--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.