embedding one language (SQL) into another (Perl) is:
awkward
ugly
error prone
difficult to maintain
difficult to test