相关疑难解决方法(0)

psycopg2将python字典插入为json

我想将一个python字典作为json插入到我的postgresql数据库中(通过python和psycopg2).我有:

thedictionary = {'price money': '$1', 'name': 'Google', 'color': '', 'imgurl': 'http://www.google.com/images/nav_logo225.png', 'charateristics': 'No Description', 'store': 'google'}

cur.execute("INSERT INTO product(store_id, url, price, charecteristics, color, dimensions) VALUES (%d, %s, %s, %d, %s, %s)", (1,  'http://www.google.com', '$20', thedictionary, 'red', '8.5x11'))
Run Code Online (Sandbox Code Playgroud)

它给出了错误消息:

thedictionary = {'price money': '$1', 'name': 'Google', 'color': '', 'imgurl': 'http://www.google.com/images/nav_logo225.png', 'charateristics': 'No Description', 'store': 'google'}

cur.execute("INSERT INTO product(store_id, url, price, charecteristics, color, dimensions) VALUES (%d, %s, %s, %d, %s, %s)", (1,  'http://www.google.com', '$20', thedictionary, 'red', '8.5x11'))
Run Code Online (Sandbox Code Playgroud)

我不知道如何从这里开始.我在互联网上找不到关于如何做这种事情的事情,我对psycopg2很新.

python postgresql dictionary psycopg2

20
推荐指数
3
解决办法
3万
查看次数

标签 统计

dictionary ×1

postgresql ×1

psycopg2 ×1

python ×1