Hi,
I am using SQLAlchemy 0.5.6 with PostgreSQL 8.4 database. The database contains
two tables Job and User with user_id as a foreign key in the Job table. I am
trying to do a join-query between these two tables as follows:
{{{
... <snip>
Job = Table('job', metadata, autoload=True)
User = Table('user', metadata, autoload=True)
# for each line in the job id file - find id, time and corresponding user's
email
for line in f:
for j in session.query(Job,User).filter(Job.c.job_runner_external_id ==
line.rstrip).filter(Job.c.user_id==User.c.id):
print j.id, j.job_runner_external_id, j.create_time,
j.update_time, j.email
</snip>...
}}}
I am trying to filter results that match particular job_runner_external_id and
join Job and User tables based user_id foreign key in Job table. The Job and
User tables have following column names common - id, create_time and
update_time. The returning query results contain id , create_time and
update_time from User table and not the Job table.
I tried specifying two temporary row-tuple variables (not sure whether that's
correct way to describe it) in the for loop as shown below, but that didn't
work:
{{{
for j, u in session.query(Job,User).filter(Job.c.job_runner_external_id
== line.rstrip).filter(Job.c.user_id==User.c.id):
}}}
{{{
Traceback (most recent call last):
File "./query_sge_killed_jobs_adv.py", line 42, in ?
for j,u in session.query(Job,User).filter(Job.c.job_runner_external_id ==
line.rstrip).filter(Job.c.user_id==User.c.id):
ValueError: too many values to unpack
}}}
Am I missing some really basic concept here? Any help?
--
Thanks,
Shantanu.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.