This is ugly to handle in the existing code. I added a test to make sure we handle it in the SQM/sql-gen re-write. In the meantime I think I have a workable solution for 5.x. Testing it now.