Postgres View Function Python Programming