Skip to content

Conversation

@joelonsql
Copy link
Contributor

The hasSingleUnnamedParam function was only checking the parameter type but not whether the parameter actually had no name.

This is just a minor bug, since it only cause a less precise error message than if adding the ppName == mempty check so functions with named parameters don't incorrectly match the single-param fallback.

create or replace function test.named_json_param(data json) returns json as $$
  select data;
$$ language sql;

--        it "rejects json body when single param has a name" $
--          post "/rpc/named_json_param"
--              [json|{"A": 1, "B": 2, "C": 3}|]

Eror before Fix:

  {
    "code": "42883",
    "message": "function test.named_json_param() does not exist",
    "details": null,
    "hint": "No function matches the given name and argument types..."
  }

Error after fix:

  {
    "code": "PGRST202",
    "message": "Could not find the function test.named_json_param(A, B, C) in the schema cache",
    "details": "Searched for the function test.named_json_param with parameters A, B, C or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.",
    "hint": null
  }

The hasSingleUnnamedParam function was only checking the parameter type
but not whether the parameter actually had no name. This caused functions
with a single NAMED parameter (e.g., `foo(data json)`) to incorrectly
match the single-param fallback mode.

The result was a confusing PostgreSQL error 42883 "function does not exist"
instead of a clean PGRST202 error explaining that no matching function
was found.

Added ppName == mempty check so functions with named parameters don't
incorrectly match the single-param fallback.
Copy link
Member

@steve-chavez steve-chavez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelonsql Nice DX improvement 👍

(Edit: CI failure for commit message should go away once I squash and merge)

@steve-chavez steve-chavez merged commit fd6a3bd into PostgREST:main Dec 15, 2025
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants