How would I go with selecting IDs from a table and...
# help
l
How would I go with selecting IDs from a table and sending those to a webhook via
net.http_post
?
s
There's an example for http_post here: https://supabase.github.io/pg_net/api/#usage_1
You could create a SQL function that selects the ids and sends it to webhook through http_post, then call that SQL function through rpc: https://supabase.io/docs/reference/javascript/rpc
l
Yeah, I've been looking at the pg_net docs and have tried to use an RPC, but no dice
s
Do you get an error?
l
I've been getting bunch of errors pointing to my SQL function 😄
Copy code
CREATE OR REPLACE FUNCTION start_tournaments() 
  RETURNS void 
AS $$
declare
  tournament_ids bigint[];
BEGIN
  select array_agg(id) from public.tournaments
  into tournament_ids;

  select
    net.http_post(
        url := 'https://webhook.site/0218ca20-e51e-4780-9147-ead73038749b',
        body := jsonb_build_object('tournament_ids', tournament_ids)
    );
END;
$$ LANGUAGE plpgsql;

select
  cron.schedule(
    'webhook-every-minute', -- name of the cron job
    '* * * * *', -- every minute
    $$
      select start_tournaments();
    $$
  );
That's the function I've been trying to run
The error I'm currently getting is
ERROR: query has no destination for result data HINT: if you want to discard the results of a SELECT, use PERFORM instead.
s
Ah, try this:
perform net.http_post
instead of
select net.http_post
l
Hey, that worked! Awesome, thank you!
Out of all the things I tried, never occurred that I could switch the
select
to
perform
in that part of the function 😄
s
😄 Cool. Glad to help!
2 Views