Fix some bug with pgsql