Hello everybody, I was wondering what I did wrong ...
# help
d
Hello everybody, I was wondering what I did wrong that my database function. It seems not to show up in RPC. The function is as followed:
Copy code
create or replace function public.getDepotStats()
RETURNS TABLE(id uuid, name varchar, number varchar, owner_id uuid, created_at timestamptz,totalExports bigint, totalGainLoss float) 
language sql
SECURITY INVOKER
AS $$
SELECT depots.id,depots.name,depots.number,depots.owner_id,depots.created_at,
     (SELECT COUNT(*) FROM depot_exports WHERE depot_exports.depot_id= depots.id) as totlaExports,
     (SELECT win_loss_amount FROM depot_exports WHERE depot_exports.depot_id= depots.id ORDER BY export_time DESC LIMIT 1) as totalGainLoss
      FROM depots
      ORDER BY depots.name;
$$;
Using Flutter/Dart as a client I get the message:
Copy code
PostgrestError (PostgrestError(message: Could not find the public.getDepotStats() function or the public.getDepotStats function with a single unnamed json or jsonb parameter in the schema cache, code: PGRST202, details: null, hint: If a new function was created in the database with this name and parameters, try reloading the schema cache.))
Any suggestions, ideas what I did wrong?
n
Hello @Devowl! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
d
I did already checked the postgrest docu and tried to run
NOTIFY pgrst, 'reload schema';
but it did not solve the problem
And just restarted my instance, but no luck
g
Seems like you are calling it with a parameter in the rpc call and you do not have a parameter in the function.
d
Mh, the calling code is quite simple:
Copy code
dart
  final response = await supabase
        .rpc('getDepotStats')
        .withConverter((data) => ModelConverter.modelList(
            data, (singleElement) => DataDepot.fromJson(singleElement)))
        .execute();
Looking into the API logs I also don't see any parameter passed
g
You used caps in your function name and did not put it in quotes
Postgres converts that to lower case all.
d
Ah ... that I did not know
Let me change that real quick 😅
g
You have to use double quotes around all caps for tables and columns. You should not use caps if possible.
d
I could have seen it... looking at the function list on the Database page
Now I can see both functions
Ok, no caps
Not a problem at all
If done right it works, thanks a lot 👍
n
Thread was archived by @Devowl. Anyone can send a message to unarchive it.