Postgres Query To Check If A Graph