python psycopg2 - ProgrammingError: function crosstab(unknown, unknown) does not exist

python psycopg2 - ProgrammingError: function crosstab(unknown, unknown) does not exist

我想在 Python 中执行具有交叉表功能的 SQL 查询,但是我收到此错误消息:

psycopg2.ProgrammingError: function crosstab(unknown, unknown) does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts.

有解决办法吗?我已经尝试升级 psycopg2(pip install psycopg2 --upgrade)。 非常感谢

您是否在架构中安装了扩展程序?

如果您运行代码:

CREATE EXTENSION tablefunc WITH SCHEMA <<YourSchema>>;

再运行,你应该可以使用你的查询了。该模块应该只需要安装一次,不需要修改您的 SQL 查询来安装它。

尝试在函数前面加上架构名称:

<<YourSchema>>.crosstab(....

如果扩展没有安装并且你想运行从 psycopg2 查询来安装它,之后立即提交连接。