Пример голого sql запроса в ОРМ SQLAlchemy.
result = db.engine.execute(
"""
SELECT
array_agg(DISTINCT t.topic) as topic,
array_agg(t.user_ask)
FROM conversation_user t
GROUP BY t.topic
"""
)
names = [row[1] for row in result]
print(names)
"""
SELECT
array_agg(DISTINCT t.topic) as topic,
array_agg(t.user_ask)
FROM conversation_user t
GROUP BY t.topic
"""
)
names = [row[1] for row in result]
print(names)