Migration to Postgres DB - SQL queries updated