fix stored procedures to work with recent postgres version
modify shebang to make it more portable
use env shebang for python