how to use Not belongs

773 views
Skip to first unread message

Pradeesh

unread,
Aug 13, 2012, 4:21:28 AM8/13/12
to web...@googlegroups.com
In my control I have an array with so many values. 
I want to write a dal query to update a table rows which having ID not in this array.

I want something like this.
db(db.table1.field1.notbelongs(array)).update(field2=False)

I have tried like this
db(db.table1.field1 not in(array)).update(field2=False) 
but this is not working fine. It is throwing an error as  raise RuntimeError, "No table selected"

I would greatly appreciate any suggestions. 

lyn2py

unread,
Aug 13, 2012, 7:09:31 AM8/13/12
to web...@googlegroups.com
I can't test it here, but did you use
db.table1.field2

instead of
field2

?

Bruno Rocha

unread,
Aug 13, 2012, 7:34:55 AM8/13/12
to web...@googlegroups.com

use the unary ~ operator

db(~db.table1.field1.belongs(array)).update(field2=False)

Bruno Rocha
www.rochacbruno.com.br

--
 
 
 

Cliff Kachinske

unread,
Aug 13, 2012, 8:10:39 AM8/13/12
to web...@googlegroups.com
Bruno's method is correct.

With Postgres and psycopg2, make sure the array variable is not empty or wrap it in a try...except block.
Reply all
Reply to author
Forward
0 new messages