gpt4 book ai didi

python - 使用 psycopg2 执行插入到 postgres 中

转载 作者:行者123 更新时间:2023-11-29 12:43:07 25 4
gpt4 key购买 nike

我正在尝试使用 psycopg2 将数据插入到 postgres 中。这是我的伪代码。好像运行没有错误,但是当我用navicat查看的时候,数据库里好像没有更新。我确实重启了 navicat 以确保。

conn = psycopg2.connect("dbname=dbname user=username password = ****  host='localhost'")
cur = conn.cursor()

在这里我尝试了直接执行和移动。

cur.mogrify("""INSERT INTO database (date, id) VALUES (now(), %s );""" % (user,))
cur.execute

我也试过这个而不是 mogrify

cur.execute("""INSERT INTO database (date, id) VALUES (now(), %s );""" % (user,))

我可以查询 select 语句,但 insert 似乎不起作用。

最佳答案

提交数据?

conn.commit()

关于python - 使用 psycopg2 执行插入到 postgres 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39177660/

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