Query by date not date + time?

28 views
Skip to first unread message

pbreit

unread,
Nov 28, 2015, 1:52:43 PM11/28/15
to web2py-users
Is it correct that if I want to search the db for items created_on a specific day (i.e., "2015-11-28") i need to compare before/after today/yesterday?

There's nothing like db(db.item.created_on.date()== "2015-11-28").select() ?

Niphlod

unread,
Nov 28, 2015, 3:37:26 PM11/28/15
to web2py-users
pydal has year, month, day, hour minutes. Anyway, for relational databases, doing a compare like that is asking them to calculate the date part for each "created_on" cell (everything on the "left side" shouldn't be a result of a function, that's database tuning 101)
This because the database would need a complete full scan on the table (any index would be disregarded). 
It's so much better (and rather easy) that you ask for an "in between" of fixed values wherever you can. And the query would be a zillion time faster. 
Reply all
Reply to author
Forward
0 new messages