Updates for postgres stored procedure to export csv