将python列表存储到数据库的最佳方式? [英] The best way to store a python list to a database?
问题描述
将python数字列表(例如[4,7,10,39,91])存储到数据库的最佳方式是什么?我使用SQLAlchemy的金字塔框架与数据库通信。
What would be the best way of storing a python list of numbers (such as [4, 7, 10, 39, 91]) to a database? I am using the Pyramid framework with SQLAlchemy to communicate to a database.
谢谢!
推荐答案
在概念上,您可以使用一对多关系将列表存储为一个表中的一行,或者您可以专注于如何在特定数据库后端存储列表。例如,postgres可以使用sqlalchemy.dialects.postgres.ARRAY数据类型将数组存储在特定单元格中,该数据类型可以将python数组序列化为postgres数组列。
Well conceptually you can store a list as a bunch of rows in a table using a one-to-many relation, or you can focus on how to store a list in a particular database backend. For example postgres can store an array in a particular cell using the sqlalchemy.dialects.postgres.ARRAY data type which can serialize a python array into a postgres array column.
这篇关于将python列表存储到数据库的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!