this was a bug never revealed because we only ever had a variable at the end of a query