From: Ben T. <bt...@gm...> - 2010-12-24 15:09:56
|
On Thu, Dec 23, 2010 at 5:58 PM, Oleg Broytman <ph...@ph...> wrote: > .select().max() produces a simple query SELECT MAX(). If you need a > query with a subquery you need to add the subquery explicitly using > sqlbuilder.Select(): > > serial = Path.select( > Path.q.serial==Select('max(serial)', staticTables=['path'])) > return serial.getOne() Thanks for your reply Oleg. I am sorry, but the above produces a bad query: -- query = Sync.select( AND( Sync.q.syncpoint==self, Sync.q.serial==sqlbuilder.Select(MAX('serial'), Sync.q.syncpoint==self, staticTables=('sync',)) ) ) -- -- SELECT sync.id, sync.syncpoint_id, sync.serial, sync.stamp, sync.status, sync.message FROM sync WHERE (((sync.syncpoint_id) = (1)) AND ((sync.serial) = (SELECT 'max(serial)' FROM sync WHERE ((sync.syncpoint_id) = (1))))); -- As you can see, the 'max(serial)' ends up inside quotes within the subselect. I can't find any MAX aggregate function to use in place of the string... Any additional hints? |