select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 42 · SYNTAX ERROR OR ACCESS RULE VIOLATION

ambiguous_function

SQLSTATE
42725
Condition name
ambiguous_function
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_AMBIGUOUS_FUNCTION
Evidence
Observed at runtime in the source evidence
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>42725 — Ambiguous function</h1>

At a glance

42725 is ambiguous_function: lookup found multiple viable candidates but no best one. The case defines uuid and jsonb overloads and passes an unknown string literal.

Meaning

Overload resolution considers literal type, casts, schema visibility, and signatures. With an unknown literal both candidates remain viable, so the parser reports function %s is not unique; this differs from 42723 (definition collision) and 42883 (no candidate). Inspect visible pg_proc rows and argument types.

Diagnosis

List visible candidates in pg_proc, including their identity arguments and input types, and inspect the inferred type of each literal. Schema qualification narrows visibility but does not choose between overloads.

Response

Cast to the type that matches the business meaning or remove an unintended overload. ::uuid selects the UUID overload here. Do not add casts merely to silence an error: they can change validation and overload behavior. In an explicit transaction, the ambiguity leaves INERROR; roll back or return to a suitable savepoint before retrying. The selected autocommit session remains IDLE.

Observed diagnostics

The fixed parser group is explicit ERROR: function %s is not unique, with the hint Could not choose a best candidate function. You might need to add explicit type casts.

Representative case

The registry creates both overloads, triggers with the unknown literal, then repeats the call with an explicit UUID cast and asserts the result.

CREATE FUNCTION syntax_schema.ambiguous_function(uuid) RETURNS text LANGUAGE SQL AS 'SELECT ''uuid''';
CREATE FUNCTION syntax_schema.ambiguous_function(jsonb) RETURNS text LANGUAGE SQL AS 'SELECT ''jsonb''';
SELECT syntax_schema.ambiguous_function('123e4567-e89b-12d3-a456-426614174000');
SELECT syntax_schema.ambiguous_function('123e4567-e89b-12d3-a456-426614174000'::uuid);

The selected 18.6 and 10.21 runs passed SQLSTATE, severity, state/recovery, repair, cleanup, and isolated-target stop assertions. See case JSON and authored evidence; private manifest and registry hashes are recorded there.

Versions

The locked catalogue contains this condition from the 7.4 presence bound through the listed snapshots. The selected natural case passed on PostgreSQL 18.6 and 10.21; that bounded result does not infer every intermediate release or every source branch.

Sources

  • src.errcodes.REL_18_6 — fixed definition at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba (source).
  • src.ambiguous-function.18.6src/backend/parser/parse_func.c lines 570–577 at 724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-256 48314eab022297478ac4e49786afaff2621ab7b1d7b50e156668cf477961384f (source).
  • src.ambiguous-function.10.23src/backend/parser/parse_func.c lines 499–506 at 02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; blob SHA-256 f1b4af88565ca01dbad2b244cd26b42f34764b3f1343b22a9231e271fb0742f2 (source).
  • src.calls.REL_18_6 / src.calls.REL_10_23 — fixed call scans, SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf / 00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.
  • manifest.42725 / snippet-registry.42725 — hashes are recorded in evidence/42725.json and each runtime record.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

42725 is the ambiguous_function condition in Class 42.

Method: Read fixed errcodes.txt and locked catalogue metadata.

Limits: Identity does not identify every backend call that can reuse this SQLSTATE.

src.errcodes.REL_18_6

The selected ambiguous_function_call follows a resolved PostgreSQL source-call group; other branches can use different dynamic fields.

Method: Trace the REL_18_6 and REL_10_23 source-call records at the locked commits.

Limits: This is one mechanism boundary, not an exhaustive inventory of the code.

src.ambiguous-function.18.6 src.ambiguous-function.10.23

The selected ambiguous_function_call passed on isolated PostgreSQL 18.6 and 10.21 targets.

Method: Run the shared SQL registry and inspect SQLSTATE, severity, state, repair, cleanup, and target stop.

Limits: Scope is limited to these statements, psycopg, and two versions.

manifest.42725 snippet-registry.42725

The locked catalogue records 42725 from the 7.4 presence bound through the listed snapshots; runtime scope is 18.6 and 10.21.

Method: Read generated facts, fixed calls, and selected summaries.

Limits: Definition presence is not an exact behavioral introduction; two runtime versions do not prove every intermediate behavior.

src.errcodes.REL_18_6 src.calls.REL_18_6 src.calls.REL_10_23

Message templates

explicit ERROR · message.ambiguous_function_call

Primary

function %s is not unique

Hint

Could not choose a best candidate function. You might need to add explicit type casts.

Reproduction & repair cases

ambiguous_function_call · PG 10, 18

Preconditions

  • A runner-owned disposable target is provisioned.

Trigger: Call two uuid/jsonb overloads with an unknown string literal.

Expected assertions

  • SQLSTATE is 42725 and the diagnostic identifies ambiguous_function(unknown)
  • The hint requests explicit type casts and the session remains IDLE
  • An explicit uuid cast selects the intended overload

Repair: Cast the input to the intended type or remove the overload ambiguity; do not guess from a function name alone.

Cleanup: Drop the runner schema and its overloads.

Recorded runtime evidence

18.6 (Homebrew) · passed

Run: syntax2-42725-latest

{
  "diagnostic": {
    "text": "function c42725_ambiguous_function_call.ambiguous_function(unknown) is not unique\nLINE 1: SELECT \"c42725_ambiguous_function_call\".ambiguous_function('...\n               ^\nHINT:  Could not choose a best candidate function. You might need to add explicit type casts.",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "42725",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "parse_func.c",
    "source_line": "577",
    "message_hint": "Could not choose a best candidate function. You might need to add explicit type casts.",
    "datatype_name": null,
    "exception_type": "AmbiguousFunction",
    "internal_query": null,
    "message_detail": null,
    "constraint_name": null,
    "message_primary": "function c42725_ambiguous_function_call.ambiguous_function(unknown) is not unique",
    "source_function": "ParseFuncOrColumn",
    "internal_position": null,
    "statement_position": "8",
    "severity_nonlocalized": "ERROR"
  },
  "repair_value": "uuid",
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "connection_autocommit": true
}
10.21 (Debian 10.21-1.pgdg90+1) · passed

Run: syntax2-42725-pg10

{
  "diagnostic": {
    "text": "function c42725_ambiguous_function_call.ambiguous_function(unknown) is not unique\nLINE 1: SELECT \"c42725_ambiguous_function_call\".ambiguous_function('...\n               ^\nHINT:  Could not choose a best candidate function. You might need to add explicit type casts.",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "42725",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "parse_func.c",
    "source_line": "506",
    "message_hint": "Could not choose a best candidate function. You might need to add explicit type casts.",
    "datatype_name": null,
    "exception_type": "AmbiguousFunction",
    "internal_query": null,
    "message_detail": null,
    "constraint_name": null,
    "message_primary": "function c42725_ambiguous_function_call.ambiguous_function(unknown) is not unique",
    "source_function": "ParseFuncOrColumn",
    "internal_position": null,
    "statement_position": "8",
    "severity_nonlocalized": "ERROR"
  },
  "repair_value": "uuid",
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "connection_autocommit": true
}

Definition snapshot: english-manuals:76a7ab4b83f0c3425c41747df72… · English manual source