I want to generate a dataframe with pandas read_sql
from my sqlalchemy query with a PostgreSQL's jsonb attribute to columns.
Actually this will give me my answer:
query = session.query(
cls.id,
cls._my_jsonb_column
).all()
pd.DataFrame.from_dict([dict(id=id_, **i) for id_,i in query])
But I would prefer to unpack the jsonb with PostgreSQL instead of in the application.
My attempt gives
query = session.query(
cls.id,
func.jsonb_to_record(cls._my_jsonb_column)
)
pd.read_sql(query.statement, query.session.bind)
(psycopg2.NotSupportedError) function returning record called in context that cannot accept type record