Ah, ok the join syntax makes sense now.. I've really just been trying things in 
the interactive python shell, and trying 'dir' to see which methods are 
available on what. My mapped fields are from sql soup, with a db from django. 
(although currently my queries are just in sql)
Hm if the join method is not meant to be there it might explain my confusion... 
So, should i always be using a select when making a query?
- is there a page that shows an example of using join with a select?
Next time i'm in front of a computer i'll have look.

Michael Bayer wrote:
> I'm not quite sure how you've arranged for query.join() to be on your  
> mapped class, but the "right side, onclause" form of query.join() uses  
> tuples.   q.join((rgt, onclause), (rgt, onclause), ...)
> On Feb 2, 2009, at 8:40 PM, Stuart Axon wrote:
>>
>> Cheers...
>>
>> Hm, still @ quite the n00b stage... got this far
>> Build.join(ExternalBuild).distinct().count()
>>
>> But when I try
>> Build.join(ExternalBuild, ExternalBuild.build_id == Build.id)
>>
>> It says:
>> Traceback (most recent call last):
>>  File "<console>", line 1, in <module>
>>  File "<string>", line 1, in <lambda>
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\util.py", line 212, in go
>>    return fn(*args, **kw)
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\orm\query.py", line 873, in join
>>    return self.__join(props, outerjoin=False,  
>> create_aliases=aliased, from_joinpoint=from_joinpoint)
>>  File "<string>", line 1, in <lambda>
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\orm\query.py", line 52, in generate
>>    fn(self, *args[1:], **kw)
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\orm\query.py", line 1071, in __join
>>    clause = orm_join(clause, right_entity, onclause,  
>> isouter=outerjoin, join_to_left=join_to_left)
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\orm\util.py", line 432, in join
>>    return _ORMJoin(left, right, onclause, isouter, join_to_left)
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\orm\util.py", line 409, in __init__
>>    expression.Join.__init__(self, left, right, onclause, isouter)
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\sql\expression.py", line 2479, in __init
>> __
>>    self.right = _selectable(right).self_group()
>>  File "c:\usr\python25\lib\site-packages\SQLAlchemy-0.5.2-py2.5.egg 
>> \sqlalchemy\sql\expression.py", line 968, in _select
>> able
>>    raise exc.ArgumentError("Object %r is not a Selectable and does  
>> not implement `__selectable__()`" % element)
>> ArgumentError: Object <sqlalchemy.sql.expression._BinaryExpression  
>> object at 0x01CB8B30> is not a Selectable and does no
>> t implement `__selectable__()`
>>
>>
>>
>>
>>
>>
>>
>> ----- Original Message ----
>> From: Michael Bayer <mike...@zzzcomputing.com>
>> To: sqlalchemy@googlegroups.com
>> Sent: Tuesday, February 3, 2009 12:58:03 AM
>> Subject: [sqlalchemy] Re: Using count with distinct?
>>
>>
>> use this:
>>
>> http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.distinct
>>
>>
>> On Feb 2, 2009, at 7:53 PM, Stuart Axon wrote:
>>
>>>
>>> I've got a fairly simple query in postgres... any idea how I do this
>>> in sqlalchemy - I couldn't find any info about this
>>>
>>> select
>>>   count(distinct device_id)
>>> from
>>>   externalbuild
>>> join
>>>   build
>>> on
>>>   build.id = externalbuild.build_id
>>> where
>>>   external_id = '1'
>>> and not
>>>   is_known
>>>
>>>
>>> BTW, the recent work looks good - might even help me convert my
>>> other queries from sql... I thought this one
>>> was the simplest, but failed here too :-\
>>>
>>>
>>>
>>>
>>>
>>>>
>>
>>
>>
>>
>>
>>
>> >
> 


      

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to