To my way of thinking, SQL queries do not belong in templates. I strictly think of templates as being presentation descriptions: concerned with “how exactly to display” information which has been supplied to them, but not with the logic that supplies that information. To me, and strictly IMHO, there is a “separation of concerns” issue here.
Template::Toolkit has many powerful features in it, which allow you to be very selective in exactly how the presentation is done. But, to me, they should be used only for that purpose. Procedural, active, logic does not belong in a template.