From: Oleg B. <ph...@ph...> - 2010-12-24 15:45:42
|
On Fri, Dec 24, 2010 at 10:09:49AM -0500, Ben Timby wrote: > 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... Oops, columns in Select cannot be strings - to allow strings in queries. Use sqlbuilder.Select(sqlbuilder.func.MAX(sqlbuilder.const.serial) from sqlobject.sqlbuilder import Select, func, const Select(func.MAX(const.serial) looks better for my eyes. Oleg. -- Oleg Broytman http://phdru.name/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |