change uniq to select for postgresql