Fix build in postgres

Wrong api and different sql per adapter were causing failures in
postgres