hoisting variable declarations out of the query body helps some T-SQL queries translate to PG/PSQL