Fix problem with postgresql

This commit fix an error in the sql query used with postgres.