Typescript Select Distinct Postgresql Create Foreign