Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Postgres: function does not exist (SQLSTATE 42883)

PostgreSQL matches functions by exact argument types. Add the cast the hint suggests, install the extension, or fix the search_path.

~4 min readSQL
#postgresql#sqlstate#type-casting#functions
Postgres function lookup diagram with mismatched argument type plates and a cast bridge

Introduction & Quick Summary

A query that looks ordinary is rejected before it runs:

code
ERROR: function lower(uuid) does not exist LINE 1: select lower(id) from users; ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQLSTATE: 42883

Quick answer: PostgreSQL resolves functions by the exact argument types, and it will not convert uuid to text on its own. Give it the type the function expects, or call the function that exists for that type:

select lower(id::text) from users; -- explicit cast select id::text from users; -- if lower() was not needed select id from users where id = '9f1c…'::uuid; -- cast the literal, not the column

The hint is the useful part: the parser found some function with that name but none whose signature matches what you passed. The usual causes are a missing cast, an extension that was never installed, a function living in a schema outside search_path, or an implicit cast PostgreSQL deliberately does not perform. This guide covers the resolution rules in the order the server applies them and the catalog queries that show what is actually callable.

Core Mechanics, Signatures & Reproducible Setup

Function lookup in PostgreSQL proceeds in fixed steps, and 42883 means none of them matched:

  1. Candidate functions with the given name, visible in search_path, are collected.
  2. Exact type matches win immediately.
  3. Only implicit casts are considered — a limited set (integer to bigint, text to varchar, and similar). There is no implicit cast from text to uuid, uuid to text, or jsonb to text.
  4. unknown literals are coerced if exactly one candidate fits.
  5. If several remain or none do, the statement fails.

A reproduction with two functions of the same name:

create table users (id uuid primary key default gen_random_uuid(), email text); insert into users (email) values ('A@EXAMPLE.COM'); select lower(id) from users; -- ERROR: function lower(uuid) does not exist select lower(email) from users; -- 'a@example.com' select lower(id::text) from users; -- works

The catalog tells you what signatures exist, which is faster than guessing:

\df lower -- Schema | Name | Result data type | Argument data types -- public | lower | text | text select p.proname, pg_get_function_identity_arguments(p.oid) as args, n.nspname as schema from pg_proc p join pg_namespace n on n.oid = p.pronamespace where p.proname in ('lower', 'to_char', 'gen_random_uuid') order by n.nspname, p.proname;

Key Comparison Table

MessageCauseFix
function lower(uuid) does not existno implicit cast to textcast the argument
function gen_random_uuid() does not existextension missing on older releasescreate extension pgcrypto
function unaccent(text) does not existunaccent extension not installedcreate extension unaccent
function public.set_updated_at() does not existfunction in another schemaqualify or fix search_path
function to_char(timestamp without time zone)wrong arityadd the format argument
operator does not exist: uuid = textoperator resolution, same codecast one side
Resolution stepWhat it acceptsExample
exact matchidentical typeslower(text)
implicit castserver-defined safe castsint4 → int8
unknown literalone candidateto_date('2026-11-28', 'YYYY-MM-DD')
named-argument matchparameter namesdate_trunc(unit => 'day', source => ts)
variadic matcharray expansionconcat_ws('-', a, b)
DiagnosisQuery
which schema is visibleselect current_schemas(true);
search path ordershow search_path;
installed extensionsselect extname, extnamespace::regnamespace from pg_extension;
function definition\df+ function_name
operator as a functionselect oprname, oprleft::regtype, oprright::regtype from pg_operator where oprname = '=';

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Cast the argument, not the whole expression

Adding a cast in the right place keeps the query sargable, which matters for indexes:

-- index on id (uuid) stays usable select * from users where id = '9f1c7a3e-0000-0000-0000-000000000000'::uuid; -- index on id may be skipped: the column is cast, not the literal select * from users where id::text = '9f1c7a3e-0000-0000-0000-000000000000';

When the function itself needs text, the cast is unavoidable, but pushing it to the literal side where possible prevents a per-row conversion.

2. Extensions that provide the function

gen_random_uuid() is built in from PostgreSQL 13, while on 12 and earlier it comes from pgcrypto. unaccent, uuid-ossp, citext and pg_trgm are separate extensions, and a restored dump can reference them without their definitions:

select gen_random_uuid(); -- ERROR: function gen_random_uuid() does not exist create extension if not exists pgcrypto; select gen_random_uuid(); -- works

On managed services the extension must also be allowed for the database; Supabase, RDS, and Cloud SQL each expose a different list of permitted extensions.

3. search_path and functions in other schemas

A function can exist and still be invisible. Compare the path with the schema that owns it, and qualify the call when the schema is not on the path:

show search_path; -- "$user", public select util.slugify('Hello World'); -- explicit schema -- or make the path explicit for the session set search_path = public, util;

This is common after moving helpers into an util or app schema, and inside SECURITY DEFINER functions where the path is set explicitly and does not include the caller's schemas.

4. Overloads and wrong arity

Same name, different number of arguments is a different function. Passing a timestamp without a format, or three arguments to a two-argument function, produces 42883 with the argument list spelled out:

select to_char(now()); -- ERROR: function to_char(timestamp with time zone) does not exist select to_char(now(), 'YYYY-MM-DD'); -- ok select substring('abcdef', 2); -- substring(text, integer) select substring('abcdef' from 2 for 3); -- SQL syntax form, same function

5. Custom functions and default arguments

A user-defined function is resolved like any other, so its schema, name and parameter types must match exactly. Recreating a function with a different signature leaves the old one in place:

create or replace function app.total(p_rows integer) returns bigint language sql as $$ select coalesce(sum(x), 0)::bigint from generate_series(1, p_rows) x $$; select app.total(5); select app.total(5::bigint); -- ok: implicit int4 -> int8 select app.total('5'); -- ok: unknown literal coerced

drop function needs the argument types for the same reason: drop function app.total(integer); removes the version you mean.

6. Operators are functions too

operator does not exist: uuid = text carries the same SQLSTATE. The cast rule is identical, and the fix is to align the two sides rather than adding a different operator:

select * from users u join events e on e.user_id = u.id::text; -- slow, and often wrong select * from users u join events e on e.user_id = u.id; -- types aligned

The second version needs events.user_id to be uuid; if it is text, fix the column type once instead of casting in every query. Reading the join plan after the change is easier with the SQL formatter, and a quick check of the column types before writing the query is faster with the SQL schema tool.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Casting the column instead of the literal. It disables the index and hides the real type mismatch.
  • create extension in the wrong schema. The function becomes invisible; use with schema public.
  • Assuming text and uuid are interchangeable. They are not, and PostgreSQL does not provide an implicit cast in either direction.
  • Dropping a function without argument types. drop function f fails or removes the wrong overload.
  • Ignoring the hint. The hint lists the argument types the server saw, which is usually enough to spot the surprise.
  • Version notes. gen_random_uuid() is built in from PostgreSQL 13 and needs pgcrypto before that. CREATE EXTENSION uses the schema named in its control file unless SCHEMA is given, and since PostgreSQL 15 non-owners cannot create objects in public, which moves helper functions into their own schema and makes search_path mistakes more common.

Official documentation: Error codes (42883) and Function type resolution.

Official references

primary documentation

The SQL documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit SQL work — they run entirely in this browser tab, so nothing you paste leaves your device.

All SQL guides

More in SQL

All SQL guides

The guides filed next to this one in SQL, in library order.