Updated for postgreSQL