Restored query export function.