fix(sql): very wrong query here and adapt for PSQL