Fix build of SQL PARTITION query