【发布时间】:2020-07-02 09:43:09
【问题描述】:
这里真的需要一些帮助。我在 Postgresql 9.5 中有一个 jsonb[] 列。 假设我在 Python 中有一个名为 history 的列表。它看起来像这样 [{'name': 'A'},{'name': 'B'},{'name': 'C'}]。使用 json.dumps(history) 之后。它看起来像 [{"name": "A"},{"name": "B"},{"name": "C"}]。
我的sql是:sql = ("INSERT INTO tableA (history_column) VALUES (%s, %s) WHERE tableA.id = %s")
connection.cursor().execute(sql, json.dumps(history), id)
我在这里遇到的问题是我无法插入json.dumps(history)。 Postgresql 显示错误消息:
`'[{"name":...
“[”必须引入明确指定的数组维度。`
我认为 json.dumps 不知何故不能很好地与 jsonb 数组配合使用。不知道有没有办法解决这个问题。
谢谢!
【问题讨论】:
标签: sql python-3.x postgresql jsonb postgresql-9.5