0

I have a procedural function (written in pl/python) which queries table A, does some calculations and then returns a set. I use this function as query for my materialized view B. Everything works perfectly except that when I want to restore my dump, I get the following error:

DETAIL: spiexceptions.UndefinedTable: relation "A" does not exist.

The line which raises this error is the last line of my sql dump:

REFRESH MATERIALIZED VIEW B;

I know that I can ignore this error and refresh my materialized view after restoration process, but I want to know why this happens? Is it because this function runs in another transaction which doesn't know anything about current restoration process? And what can I do to prevent this error?

4
  • 1
    Are you sure it's called A and not a? Your view is called b yet you refer to it as B. ("I use this function as query for my materialized view B.") but REFRESH MATERIALIZED VIEW B refreshes a view called b not B. In case it's not clear, quoting an identifier makes it case sensitive, not quoting results in the identifier being all lowercase regardless of what you wrote. As you're not quoting B it will be b. Since it didn't say that b doesn't exist, the b view exists, but A doesn't. Since your view is lowercase, I suspect your table is too. Commented Nov 14, 2019 at 15:20
  • The other possibility is that you forgot to schema qualify the table, and search_path is different. Commented Nov 14, 2019 at 16:18
  • No, it isn't relevent to table names. As I said, it works when I refresh it manually. Commented Nov 14, 2019 at 16:51
  • My table is not schema qualified. I only have public schema and as I said, it works when I run refresh command manually. Commented Nov 14, 2019 at 16:53

1 Answer 1

1

For security reasons, pg_dump (or pg_restore) emits a command which empties the search_path, so when you restore the process gets run with an empty search path. But it does not edit the text body of your function at all but emits it as-is, so it can't alter it to specify the fully qualified name of the table. So the function can't find the table when run inside the process doing the restore.

You can fully qualify the table name in the function, or you can define the function with SET search_path = public. Or you can edit the dump file to remove the part that clears the search_path, if you are not concerned about the security implications.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. That was the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.