Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread NiL
Hi, thank you for your help, and the effort at writing a good piece of code. however, while playing around with, and trying to execute it in PGAdmin, I stumbled upon some problems the q = Session().query(Group).join(all_parents, all_parents.c.id==Group.id) generates a SQL like (I've

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread Michael Bayer
On Aug 12, 2011, at 6:00 AM, NiL wrote: Hi, thank you for your help, and the effort at writing a good piece of code. however, while playing around with, and trying to execute it in PGAdmin, I stumbled upon some problems the q = Session().query(Group).join(all_parents,

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread NiL
hi again, after playing a while with PG, here is a SQL statement that outputs the expected result SELECT groups_recursive.id AS groups_recursive_id, groups_recursive.name AS groups_recursive_name, groups_recursive.display_name AS groups_recursive_display_name FROM groups_recursive JOIN (WITH

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread Michael Bayer
sure, couple of small adjustments, attached On Aug 12, 2011, at 10:44 AM, NiL wrote: hi again, after playing a while with PG, here is a SQL statement that outputs the expected result SELECT groups_recursive.id AS groups_recursive_id, groups_recursive.name AS groups_recursive_name,

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread NiL
thank you so much Michael !! much better few last things are WITH RECURSIVE all_parents(id, rank) AS SELECT groups_recursive.id, 1 FROM groups_recursive, groups_recursive_parents__groups_recursive_children quotes around the 1, this leads to ERROR: column 1 does not exist + the param

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread Michael Bayer
its at the point where you should be able to tweak it using documented processes. column() applies quotes for example, whereas literal_column(1) would not. Same for an expression x + 1 will turn the 1 into a bind, would not if you again use literal_column()

Re: [sqlalchemy] joining to a from_statement

2011-08-12 Thread NiL
yes, many thanks I now have a method in my Group class (still in elixir syntax) def hierarchy_ng(self): with CommonTableExpression.create( all_parents, [id, rank]) as all_parents: rank = literal_column(rank) groups = Group.table groups_assoc =

Re: [sqlalchemy] joining to a from_statement

2011-08-11 Thread Michael Bayer
On Aug 11, 2011, at 12:31 PM, NiL wrote: Hi list, I'm using SA 0.6.7, Python 2.6.5 and Postgres 8.4 on Ubuntu 10.04 LTS I'm trying to optimize my code against postgres by using the recursive statements CTE as documented here :