[web2py] Re: How to delete records where db.table.field value doesnt exist in list?

2014-10-09 Thread Anthony
db(~db.people.name.belongs(namelist)).delete()

Anthony

On Thursday, October 9, 2014 1:45:23 PM UTC-4, Niels Jensen wrote:

 Hi,

 I have a list of names
 namelist = ['Niels', 'Bob', 'Frank', 'Pat', 'Ann']

 I'd like to remove all records from a table where the name field does not 
 have a name in the list.
 For example if all the above exist in the table 
 Is there a function to do this or will I need to loop through each row in 
 the table. I was thinking something like this might work?


 rows = db(db.people.name != namelist).select()
 del db.mytable[rows]







-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to delete records where db.table.field value doesnt exist in list?

2014-10-09 Thread Niels Jensen
Thanks!  So simple,  I reread the docs after your reply and can't believe I 
missed it.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.