在PostgreSQL下有很多个不同模式(SCHEMA),psycopg2连接指定默认public的模式。
在正常的情况下,连接PostgreSQL不会爆错,但是在使用sql对数据库进行操作时,会爆出以下错误信息:
current transaction is aborted, commands ignored until end of transaction block
解决方案:
psycopg2.connect(dbname=PostgreSQL的数据库名,
user=用户名,
password=密码,
host=IP地址,
port=端口,
options="-c search_path=other_schema,public")
注意:
- dbname=PostgreSQL的数据库名,并不是模式
- options=“-c search_path=other_schema,public”),other_schema是你想要的那个模式
sql示例:

注意:
- 列名的获取
- 表名“table”还是table
当使用psycopg2连接到PostgreSQL数据库,默认进入public模式,但在执行SQL时遇到错误currenttransactionisaborted,commandignoreduntilendoftransactionblock。解决方法是在连接参数中设置options-csearch_path=other_schema,public,将other_schema替换为所需模式。这允许指定默认搜索路径,避免错误。
1286

被折叠的 条评论
为什么被折叠?



