Postgres Check If Column Exists In Dataframe Group By Aggregate