Scratching my head on how one would be able to do the following simplified
psql snippet in python-sql (where account_account is targetted twice):
select j.id, j.code, j.name, j.type, s.name, dda.code, dca.code
from account_journal j join ir_sequence s on s.id = j.sequence_id
join account_account dda on dda.id = j.default_debit_account_id
join account_account dca on dca.id = j.default_credit_account_id

If I try a single Table() definition, the following:
account_account = Table('account_move')
#dda = Table('account_move')
#dca = Table('account_move')
account_move = Table('account_move')
account_journal = Table('account_journal')
ir_sequence = Table('ir_sequence')

query = account_journal.join(
    account_move,
    condition=account_move.journal_id == account_journal.id)

query = query.join(
    ir_sequence,
    condition=ir_sequence.id == account_journal.sequence_id)

query = query.join(
    account_account.as_('dda'),
    condition=dda.id == account_journal.default_debit_account_id)

query = query.join(
    account_account.as_('dca'),
    condition=dca.id == account_journal.default_credit_account_id)

query = query.select(
    account_journal.id, account_journal.code, account_journal.name,
account_journal.type, ir_sequence.name.as_('sequence_name'), dda.code.as_('default_debit_account'), dca.code.as_('default_credit_account'))

cur.execute(*query)


I get
    account_account.as_('dda'),
TypeError: 'Column' object is not callable


If I try the style with two differently named tables(and the joined
table names appropriately updated, I get:
    cur.execute(*query)
  File "/usr/lib/python3.6/site-packages/psycopg2/extras.py", line 316, in execu
te
    return super(NamedTupleCursor, self).execute(query, vars)
psycopg2.ProgrammingError: ERREUR:  la colonne d.code n'existe pas
LINE 1: ..., "a"."code", "a"."name", "a"."type", "c"."name", "d"."code"...
                                                             ^
HINT:  Peut-être que vous souhaitiez référencer la colonne « a.code » ou la colo
nne « c.code ».


any hint on how to do this?
--

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.

Reply via email to