Rethink SQL generator function.