2
votes

I would like to execute an SQL query which has crosstab function in Python, however I get this error message:

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.

Is there a workaround? I already tried upgrading psycopg2 (pip install psycopg2 --upgrade). Thanks a lot

2

2 Answers

5
votes

Try to precede function with schema name:

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

In case extension wasn`t installed and You want to run query from psycopg2 to install it, commit connection right after.

2
votes

Have you installed the extension in your schema?

If you run the code:

CREATE EXTENSION tablefunc WITH SCHEMA <<YourSchema>>;

And rerun, you should be able to use your query then. The module should only need to be installed once, won't need to modify your SQL query to install it.