Fixed generated SQL for tagged_with :any

Closes #519.