To me the book example is not logic :

>>> rows = db(db.person).select(join=db.person.on(db.person.id==db.dog.owner))
>>> for row in rows:
    print row.person.name, 'has', row.dog.name
Alex has Skipper
Alex has Snoopy
Bob has Puppy


How I understand the syntax is that I will do a join on the table already in
the from db(db.person)... And it's what the console seems to failed with...

What I need is :

SELECT *
FROM t1
INNER JOIN t2
  ON(t2.id = t1.t2_id)

But what rows1 = db(db.t1).select(join=db.t1.on(db.t1.t2_id == db.t2.id))
return that failed seems to be :

SELECT *
FROM t1
INNER JOIN t1
  ON(t2.id = t1.t2_id)

Richard


On Fri, Oct 21, 2011 at 10:48 AM, Richard Vézina <
[email protected]> wrote:

> Ok, but I am pretty much confuse with the syntax...
>
> I try with my own tables by kind of translating person and dog to adapt to
> my need but it failed...
>
> This work :
>
> rows = db(db.t1.t2_id == db.t2.id).select()
> for row in rows:
>     print row.t2.f1 + '-' + row.t1.f1
>
> But this don't work :
>
> rows1 = db(db.t1).select(join=db.t1.on(db.t1.t2_id == db.t2.id))
> So can't execute the lines below since the upper line has failed...
> #for row in rows1:
> #    print row.t2.f1 + '-' + row.t1.f1
>
> In console I get those errors :
>
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (1376, 0))
>
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (1386, 0))
>
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (1306, 0))
>
>
> The only way I can execute the query (db().select()) :
> rows1 = db(db.t1).select(join=db.t2.on(db.t2.id == db.t1.t2_id))
> for row in rows1:
>     print row.t2.f1 + '-' + row.t1.f1
>
> In this case the for failed with with the t2.f1 since there is only t1 rows
> in the output of the request (print(rows1))...
>
> Where's my mystake?!
>
> Richard
>
> On Fri, Oct 21, 2011 at 10:35 AM, Anthony <[email protected]> wrote:
>
>> Yes, I think you could always do inner joins, and the new select(join=...)
>> syntax was introduced in 1.96.1.
>>
>> On Friday, October 21, 2011 10:15:09 AM UTC-4, Richard wrote:
>>>
>>> Hello,
>>>
>>> I would like to make sure the inner join syntax was available in
>>> 1.98.2 ?
>>>
>>> Thanks.
>>>
>>> Richard
>>
>>
>

Reply via email to