Re: [web2py] complex query with delete

2012-05-14 Thread Vincenzo Ampolo
On 05/13/2012 02:50 PM, Anthony wrote: ids = db()._select(db.users_keywords.keyword_id, distinct=True) db((~db.keyword.id.belongs(ids)) (db.keyword.dictionary == dictionary)). delete() Anthony Thanks a lot! This is exactly what I was looking for! -- Vincenzo Ampolo

Re: [web2py] complex query with delete

2012-05-14 Thread Cliff
Vincenzo, You may get exceptions from the database driver if the id list is empty. Using Postgres, I do something like this: ids = db()._select(db.users_keywords.keyword_id, distinct=True) if len(ids): db((~db.keyword.id.belongs(ids)) (db.keyword.dictionary == dictionary)). delete()

Re: [web2py] complex query with delete

2012-05-14 Thread Anthony
You may get exceptions from the database driver if the id list is empty. Using Postgres, I do something like this: ids = db()._select(db.users_keywords.keyword_id, distinct=True) if len(ids): db((~db.keyword.id.belongs(ids)) (db.keyword.dictionary == dictionary)). delete()

Re: [web2py] complex query with delete

2012-05-13 Thread Vincenzo Ampolo
On 05/13/2012 12:02 AM, Andrew wrote: Does replacing select with delete work? Nope, i got: TypeError: delete() got an unexpected keyword argument 'join' It seems that delete does not accept any argument at all! Yeah. I want to delete from db.keyword If delete was more like select() would

Re: [web2py] complex query with delete

2012-05-13 Thread Anthony
db((db.keyword.id!=db.users_keywords.keyword_id)(db.keyword.dictionary==dictionary)).delete(db.keyword) Exactly what set of records are you trying to delete from db.keyword? Are you trying to identify keywords that are not referenced by any records in db.users_keywords? If so, how about

[web2py] complex query with delete

2012-05-12 Thread Vincenzo Ampolo
Hi, In the web2py book I've seen simple delete queries like: db(db.person.id 3).delete() where it's easy to understand that the persons with id 3 will be deleted from db.person.id but what if i want to delete rows selected with this query:

[web2py] complex query with delete

2012-05-12 Thread Andrew
Not that I've tried it, but does this syntax from the book help ? rows = db(db.person).select(join=db.dog.on(db.person.id==db.dog.owner)) Does replacing select with delete work?

[web2py] complex query with delete

2012-05-12 Thread Andrew
P.s. I assume you are wanting to delete from keyword ? That is why it is ambiguous with joins, which one is the target ?