Rework to make both Postgres and Mysql happy