Error: Function Does Not Exist
Issue
During a historical sync or table re-sync, one table repeatedly fails to sync while other tables sync successfully. The logs show the following error, even though the function exists in the source database:
ERROR: function <nested_function_name>() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Where: SQL function "<outer_function_name>" during startup
Environment
Connector: PostgreSQL
Resolution
To resolve this issue:
Identify the two functions in the error message:
- The outer function appears after
Where: SQL function. PostgreSQL runs this function when reading the affected table, such as through a generated column, a default expression, a view, or a row-level security policy. - The nested function appears after
ERROR: function. The outer function calls this function, but PostgreSQL can't resolve the call.
- The outer function appears after
Run the following query to confirm that the nested function exists and find its schema:
SELECT n.nspname AS schema_name, p.proname AS function_name FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace WHERE p.proname = '<nested_function_name>';Confirm that the Fivetran database user has
USAGEon the schema containing both functions andEXECUTEon both functions:GRANT USAGE ON SCHEMA <schema_name> TO <fivetran_user>; GRANT EXECUTE ON FUNCTION <schema_name>.<nested_function_name>() TO <fivetran_user>;Update the outer function using one of the following options:
- Add a
SET search_pathclause to the outer function's definition that includes the nested function's schema:ALTER FUNCTION <schema_name>.<outer_function_name>() SET search_path TO <schema_name>, public; - Schema-qualify the nested call inside the outer function's body. For example, replace
<nested_function_name>()with<schema_name>.<nested_function_name>().
- Add a
If you deselected the table in step 2, re-select it:
i. In Fivetran, go to your PostgreSQL connection page.
ii. Select the Schema tab.
iii. Select the checkbox next to the affected table.
iv. Click Save Changes.
If the issue persists, contact our support team.
Cause
This issue occurs when a function that PostgreSQL runs while reading a table calls another function without a schema prefix, and the nested function's schema isn't in the Fivetran session's search_path.
PostgreSQL uses search_path to resolve function names without a schema prefix. The Fivetran session can use a different search path from your database administrator's session. As a result, the same function call may succeed during administrator testing but fail during the sync. When this happens, PostgreSQL returns the same error on every attempt, and we can't complete the sync for that table.