gpt4 book ai didi

python - SQLAlchemy 从查询中获取 ID 列表

转载 作者:太空狗 更新时间:2023-10-29 21:39:55 30 4
gpt4 key购买 nike

如何获取 ID 列表而不是 SQLAlchemy 对象列表?目前我正在这样做:

[x.id for x in random_query.all()]

有没有更好的方法,最好只使用 SQLAlchemy 语句。

最佳答案

数据库

 SELECT DISTINCT `id` FROM `table`;

python

 for value in Session.query(Table.id).distinct():
#Do something Append

关于python - SQLAlchemy 从查询中获取 ID 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24560945/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com