Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call function that has multiple unnamed (positional) parameters #599

Closed
2 tasks done
nikmartin opened this issue Jan 28, 2025 · 2 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@nikmartin
Copy link

nikmartin commented Jan 28, 2025

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Given the function:

create or replace function hello_world(integer, integer) returns text as $$
  select 'Hello world ' || $1 || ' ' || $2 ;
$$ language sql;

then calling it via:

 this.postgrest.rpc('hello_world',[2,4]).then((res: any) => {
      console.log(res)
    });

results in this message:

{
    "error": {
        "code": "PGRST102",
        "details": null,
        "hint": null,
        "message": "All object keys must match"
    },
    "data": null,
    "count": null,
    "status": 400,
    "statusText": "Bad Request"
}

If I recompile the function to take no parameters, I can call it fine.

To Reproduce

Create a function:

create or replace function hello_world(integer, integer) returns text as $$
  select 'Hello world ' || $1 || ' ' || $2 ;
$$ language sql;

NOTIFY pgrst, 'reload schema';

Call the function from pgAdmin:

select hello_world(5,7);

Call from Javascript app:

this.postgrest.rpc('hello_world',[2,4]).then((res: any) => {
      console.log(res)
    });

Expected behavior

To be able to pass multiple unnamed parameters to a function via an array in the rpc method

System information

  • OS: Ubuntu (Docker containers running latest PostGIS and PostGREST)
  • Browser (if applies): MS Edge
  • Version of supabase-js: [e.g. 1.18.1]
@nikmartin nikmartin added the bug Something isn't working label Jan 28, 2025
@nikmartin
Copy link
Author

I learned from PostgREST that this is by design, and it will only accept a single unnamed parameter. I will need to wrap the PostGIS and pgRouting functions in my own wrapper functions to take a single json argument

@laurenceisla
Copy link
Contributor

it will only accept a single unnamed parameter.

Yes, if you only want unnamed parameters. If you still want multiple parameters, then naming them is the solution.

-- instead of 
create or replace function hello_world(integer, integer) returns text as $$
-- do
create or replace function hello_world(paramA integer, paramB integer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants