Postgres Select Ids Into Array In Python Syntax For If Else Statements