Fixing queries not working in databases other than MySQL.
FIX: Fixed PGSQL incompatabilities