Incident Response

PostgreSQL "ERROR: function does not exist": Causes and Fixes

The function usually does exist. PostgreSQL just could not match it by name, schema and argument types. Here is how to tell which of the three failed, and why the error appears after restores, upgrades and pooler changes.

· 15 min read · AG Data Team

ERROR: function … does not exist in PostgreSQL rarely means the function is really gone. It means the parser could not find a function that matches all three things at once: the name, a schema in the current search_path, and the argument types of this particular call. Work out which of the three failed and the fix is usually one cast, one schema name or one CREATE EXTENSION.

What PostgreSQL is telling you

The error carries SQLSTATE 42883 (undefined_function). Look closely at the signature in the message: it shows the argument types PostgreSQL saw at the call site, not the ones you meant to pass (parse_func.c).

SELECT round(avg_price, 2) FROM daily_stats;

ERROR:  function round(double precision, integer) does not exist
LINE 1: SELECT round(avg_price, 2) FROM daily_stats;
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Here the column is double precision. The only two-argument round takes numeric and integer (math functions), and double precision converts to numeric only on assignment, not implicitly (pg_cast.dat). No candidate matches, so you get "does not exist", even though round obviously exists.

The parser looks up functions much like tables: an unqualified name is searched through the schemas in search_path, and pg_catalog is always searched first unless you list it explicitly (schema search path). Among the functions it finds, it picks one whose argument types match exactly or can be reached through implicit casts (function type resolution). If several match equally well you get a different error, function … is not unique. If the name exists but is a procedure, you get … is a procedure with the hint "To call a procedure, use CALL."

PostgreSQL 19 tells you more. Up to version 18 the usual hint is the generic "You might need to add explicit type casts.", even when types have nothing to do with it. PostgreSQL 19 adds a DETAIL line that says which check failed: there is no function of that name, a function of that name exists but not in the search_path, no version takes this number of arguments, or none takes these argument names or types (parse_func.c, REL_19_STABLE). On 19, read the DETAIL line first.

-- PostgreSQL 19: the DETAIL line says which check failed
ERROR:  function uuid_generate_v4() does not exist
DETAIL:  A function of that name exists, but it is not in the search_path.

Step 1: find every function with that name

Don't guess. Ask the catalog for every overload in every schema and compare it with what your session searches. current_schemas(true) shows the effective path, including pg_catalog, and leaves out schemas that do not exist or cannot be searched (system information functions).

-- every function with this name, in every schema, with its full signature
SELECT p.oid::regprocedure AS signature,
       n.nspname          AS schema,
       p.prokind          AS kind      -- f function, p procedure, a aggregate, w window
FROM pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
WHERE p.proname = 'uuid_generate_v4';

-- what this session actually searches, including pg_catalog
SHOW search_path;
SELECT current_schemas(true);

-- the same in psql
\df *.uuid_generate_v4

The result points to one of the causes below. No rows means the function is not in this database at all. Rows in a schema that is missing from current_schemas point to a search path problem. Rows with different argument types mean a type mismatch.

The usual causes and their fixes

  1. Argument types don't match. The round(double precision, integer) case above is the classic one. The same happens with a text parameter passed to a function that takes bigint, or a varchar column passed to a function written for uuid. Cast at the call site, or add an overload if many callers need it. Untyped string literals are flexible, but parameters that a driver sends with an explicit type are not, so a query can work in psql and fail from the application.
  2. The function is in a schema outside search_path. Schemas you have no USAGE on are silently skipped as well (search_path), so a missing grant also shows up as "does not exist". Schema-qualify the call, or set the path for the role or database instead of per session. The same lookup rules apply to tables, see our guide to "relation does not exist".
  3. The extension is installed in another database. CREATE EXTENSION loads objects into the current database only (CREATE EXTENSION). uuid_generate_v4() working in appdb says nothing about appdb_staging. If all you need is a random UUID, the built-in gen_random_uuid() needs no extension (UUID functions).
  4. Case and quoting. CREATE FUNCTION "GetUser"() keeps the capital letters, but a call to GetUser() without quotes is folded to getuser. Use lower-case names.
  5. Wrong number of arguments or names. A call must supply every parameter that has no default. After a refactor, callers that pass named arguments by the old names stop matching.
  6. A procedure called with SELECT, or a function called with CALL. These produce their own error and hint, as described above.
-- round(numeric, integer) is the only two-argument round()
SELECT round(avg_price::numeric, 2) FROM daily_stats;

-- a text parameter passed to an integer function
SELECT get_order($1::bigint);
-- schema-qualify the call (most robust)
SELECT extensions.uuid_generate_v4();

-- or fix the path for a role or a database, not per session
ALTER ROLE app_user SET search_path = app, extensions, public;
ALTER DATABASE appdb SET search_path = app, extensions, public;

-- the extension is missing in THIS database
CREATE SCHEMA IF NOT EXISTS extensions;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA extensions;

Functions that call other functions

A function body written as a string is resolved when it runs, using the caller's search_path. A helper that works from the application can fail for a user, a job or a maintenance command with a different path. You can attach a path to the function with SET search_path, or (since PostgreSQL 14) write SQL functions with a SQL-standard body, which is parsed when the function is created (CREATE FUNCTION). A SET clause has a cost: PostgreSQL does not inline SQL functions that have one (clauses.c), so for small hot functions the standard body is often the better choice.

-- an index expression that calls a helper without a schema
CREATE FUNCTION app.normalize_email(text) RETURNS text
  LANGUAGE sql IMMUTABLE
  AS 'SELECT lower(trim(app.strip_tags($1)))';

-- pin the path on the function itself
ALTER FUNCTION app.normalize_email(text) SET search_path = app, pg_catalog;

-- or (PostgreSQL 14+) use a SQL-standard body, resolved at creation time
CREATE OR REPLACE FUNCTION app.normalize_email(t text) RETURNS text
  LANGUAGE sql IMMUTABLE
  RETURN lower(trim(app.strip_tags(t)));

What changes on large systems

On a laptop this error comes from a typo. In production it usually shows up right after something changed the environment around the function.

-- functions whose body may depend on the caller's search_path
SELECT p.oid::regprocedure, l.lanname
FROM pg_proc p
JOIN pg_namespace n ON n.oid = p.pronamespace
JOIN pg_language l ON l.oid = p.prolang
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
  AND p.proconfig IS NULL          -- no SET clause
  AND p.prosqlbody IS NULL         -- not a SQL-standard body
  AND l.lanname IN ('sql', 'plpgsql')
ORDER BY 1;

The audit query is broad on purpose. Many listed functions are fine, but each one that calls other user objects without a schema name is a candidate for a SET clause or a standard body.

Key takeaways

PostgreSQL Errors SQL Upgrades
Work with us

Errors after an upgrade or restore?

We upgrade and migrate production PostgreSQL clusters, including extensions, functions and search_path settings, and test the result before traffic moves.

Get in touch More from the blog