Le 05/09/2017 à 15:14, Richard PALO a écrit :
any hint on how to do this?
noticing an interesting example in the python-sql overview, I tried the following and it seems to hack it out:
account_move = Table('account_move') account_journal = Table('account_journal') ir_sequence = Table('ir_sequence') j1 = account_journal.join( account_move, condition=account_move.journal_id == account_journal.id) j2 = j1.join( ir_sequence, condition=ir_sequence.id == account_journal.sequence_id) j3 = j2.join(Table('account_account')) j3.condition = j3.right.id == account_journal.default_debit_account_id j4 = j3.join(Table('account_account')) j4.condition = j4.right.id == account_journal.default_credit_account_id query = j4.select( account_journal.id, account_journal.code, account_journal.name, account_journal.type, ir_sequence.name.as_('sequence_name'), j3.right.code.as_('default_debit_account'), j4.right.code.as_('default_credit_account'), distinct_on=account_journal.id) print(query) cur.execute(*query) for jnl in cur: print(jnl.id, jnl.code, jnl.name, jnl.type, jnl.sequence_name, jnl.default_debit_account, jnl.default_credit_account)
The print statement pretty much shows the query I intended though what I don't get now is why python-sql needs the 'distinct_on' clause to avoid excessive output... that is, neither psql nor phppgadmin sql need it to work correctly. Is this an anomalie that perhaps should have an issue filed? -- Richard PALO -- You received this message because you are subscribed to the Google Groups "python-sql" group. To unsubscribe from this group and stop receiving emails from it, send an email to python-sql+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.