我正在尝试使用Python运行一个查询,并使用psycopg2连接到PostgreSql。我可以连接,但无法运行以“grant select on…”开头的权限查询
我试过做常规的“select*fromcolumnlimit1”,看看是否建立了连接,并且我能够进行常规查询。我已尝试“将视图上的选择授予用户”,但不起作用。你知道吗
permissions = "grant select on view_activities to username;"
try:
cur.execute(permissions)
contents = "The permissions have been run"
message = twilioCli.messages.create(body = contents, from_=twil, to = me)
except:
contents = "The permissions have failed"
message = twilioCli.messages.create(body = contents, from_=twil, to = me)
预期结果是收到一条文本消息,说明“权限已运行”,这表示此查询运行时没有问题。但是,我得到的是第二个结果“the permissions have failed”,这表明查询没有正确运行。我的理论是postgres无法运行Python的'grant select…'语法。你知道吗
似乎您的代码的某个部分(可能没有添加到这里)正在执行
cursor.fetchall()
和cursor.fetchone()
,这给了我同样的例外psycopg2.ProgrammingError: no results to fetch
。一旦我删除了.fetchall()
或.fetchone()
,我的代码执行起来就没有任何问题。你知道吗另外,确保在执行
GRANT
之后运行connection.commit()
,否则它将被回滚。你知道吗相关问题 更多 >
编程相关推荐