Re: [sqlalchemy] distinct query

2010-03-19 Thread Sebastian Elsner
Hello, qry = session.query(AssetCategory).join(Asset).join(Shot).filter(Shot.id==1).distinct() this one already did the trick. qry = qry.filter(Shot.id==shot_id_of_interest) what did you add this for? The results seem to be identical... that generates SELECT DISTINCT AssetCategory.id

[sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Stodge
Ok so far I have this: expressions = [] for tag in tag_list: expressions += session.query(Document).filter(Tag.tag==tag) documents = session.query(Document).join(Document.tags).filter(and_(*expressions)) Doesn't work but it's progress! :) On Mar 18, 2:37 pm, Stodge sto...@gmail.com

[sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Stodge
Now we're getting somewhere: expressions = [] for tag in tag_list: expressions += [Tag.tag==tag] documents = session.query(Document).join(Document.tags).filter(and_(*expressions)) Thanks to a Storm example I found. :) On Mar 19, 8:12 am, Stodge sto...@gmail.com wrote: Ok so far I have

Re: [sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Michael Bayer
select document.* from document join tags on document.id=tags.document_id where tags.tag='foo' and tags.tag='bar' and tags.tag= am I missing something ? that would return no rows in most cases. if you want to find documents that have an exact list of tags, you'd have to do something like

[sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Stodge
Thanks. That doesn't quite work. Based on my data, the following should (and does) work because it only returns document id=1, which only has these two tags: tag_list = ['my document', 'source code'] session.query(Document).\ filter(Document.tags.any(Tag.tag.in_([t for t in tag_list]))).\

[sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Stodge
Getting closer. Maybe something like this: q1 = session.query(Document).join(Document.tags).filter(Tag.tag=='my document') q2 = session.query(Document).join(Document.tags).filter(Tag.tag=='source code') q3 = q1.intersect(q2) q4 = session.query(Document).filter(Document.title=='Source Code') print

Re: [sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Conor
Stodge wrote: Thanks. That doesn't quite work. Based on my data, the following should (and does) work because it only returns document id=1, which only has these two tags: tag_list = ['my document', 'source code'] session.query(Document).\ filter(Document.tags.any(Tag.tag.in_([t for t

[sqlalchemy] inner join and ambiguous columns

2010-03-19 Thread marco vaccari
Consider 3 tables A,B,C A JOIN B ON A.id = B.id produce all the columns required for an insert into C. I can write: C.insert().values(dict(zip(record.keys(), record.items())) With use_labels == True and fold_equivalents == False the above solution does not work because the join columns labels

[sqlalchemy] Re: inner join and ambiguous columns

2010-03-19 Thread marco vaccari
Opsss! dict(zip(record.keys(), record.items()) must be dict(record.items()) On 19 Mar, 16:23, marco vaccari agat...@gmail.com wrote: Consider 3 tables A,B,C A JOIN B ON A.id = B.id produce all the columns required for an insert into C. I can write:

[sqlalchemy] Refresh() for update

2010-03-19 Thread Kent
With query() I can add with_lockmode('for update'). Can I do so on a session.refresh()? What about a get()? I see this as a useful approach to a two phase large query, where one wants to avoid locking a large number of rows. First you would issue a non-locking query and then, once you have a

[sqlalchemy] how to specify database engine

2010-03-19 Thread Gijo mathew
Hi guys, i am using SA 0.5.5. Is it possible to specify the database engine while connecting t the database. i want to use INNODB for mysql, default is myisam right now i am changing the storage engine in mysql conf file. but this will be applied for the whole db. i need only one db with innodb

Re: [sqlalchemy] Refresh() for update

2010-03-19 Thread Michael Bayer
On Mar 19, 2010, at 12:34 PM, Kent wrote: With query() I can add with_lockmode('for update'). Can I do so on a session.refresh()? What about a get()? a get() yes. a refresh() no, but that's a fine idea so I've committed a flag for that in rab5a31b4f3bf. A substitute is

Re: [sqlalchemy] inner join and ambiguous columns

2010-03-19 Thread Michael Bayer
On Mar 19, 2010, at 11:23 AM, marco vaccari wrote: Consider 3 tables A,B,C A JOIN B ON A.id = B.id produce all the columns required for an insert into C. I can write: C.insert().values(dict(zip(record.keys(), record.items())) With use_labels == True and fold_equivalents == False the

[sqlalchemy] Re: in_() operator is not currently implemented for many-to-one-relations - alternatives?

2010-03-19 Thread Stodge
Thanks! That worked beautifully. :) On Mar 19, 11:18 am, Conor conor.edward.da...@gmail.com wrote: Stodge wrote: Thanks. That doesn't quite work. Based on my data, the following should (and does) work because it only returns document id=1, which only has these two tags: tag_list = ['my

Re: [sqlalchemy] Refresh() for update

2010-03-19 Thread Kent Bower
By the way, must get() always accept a primary key? For composite keys is there a shortcut to access its ident (in the correct order)? (So I could get the ident tuple and pass it to get() with populate_existing()) On Mar 19, 2010, at 1:12 PM, Michael Bayer mike...@zzzcomputing.com

[sqlalchemy] Re: Refresh() for update

2010-03-19 Thread Kent
obj._sa_instance_state.sort_key?? Will that always be sorted how get() expects? Is there a more public way to get that? On Mar 19, 1:42 pm, Kent Bower k...@retailarchitects.com wrote: By the way, must get() always accept a primary key?  For composite   keys is there a shortcut to access its

Re: [sqlalchemy] Refresh() for update

2010-03-19 Thread Michael Bayer
if you have an instance already, you're looking for object_mapper(instance).primary_key_from_instance(instance). On Mar 19, 2010, at 1:42 PM, Kent Bower wrote: By the way, must get() always accept a primary key? For composite keys is there a shortcut to access its ident (in the correct

[sqlalchemy] ObjectDeletedError

2010-03-19 Thread Shawn Church
I'm trying to refactor an existing cherypy/pyamf application and am running into the following problem. The code: @RemoteClass(alias=common.model.vo.OrderVO) class OrderVO(object): pass class Orders(Service): Query and modify model.application.Order klass = model.Order @secure()