将数组插入postgres数组

2024-06-07 04:43:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将数组作为数组插入到postrges表中。我收到以下错误:

jobsArray = ['Vice President', 'Technical Services Consultant']

db.execute("""INSERT INTO test VALUES (%s)""", (jobsArray,))

TypeError: not all arguments converted during string formatting

我尝试过许多不同的解决方案,推荐stackoverflow,但都没有成功,错误各不相同,但这是最常见的错误。我试着转换成元组,但行为相同。在


Tags: testexecutedbvice错误数组insertvalues
1条回答
网友
1楼 · 发布于 2024-06-07 04:43:24

我认为Postgres数组语法使用大括号。来源:https://www.postgresql.org/docs/9.1/static/arrays.html

如果您使用的是SQLAlchemy,它可以自动执行转换,但是我相信您需要为您的表创建一个数据模型。在

相关问题 更多 >