Postgres Flatten Array Python Memory