supabase / pg_net

A PostgreSQL extension that enables asynchronous (non-blocking) HTTP/HTTPS requests with SQL
https://supabase.github.io/pg_net
Apache License 2.0
213 stars 16 forks source link

Error with net.http_post : query has no destination for result data #130

Closed Oksitaine closed 5 months ago

Oksitaine commented 5 months ago

Bug report

Describe the bug

I want to make a HTTP POST request with supabase and for that i use a trigger in my table. This post request need to have a headers for a token so i use pg_net for that. I install the pg_net extensions with the supabase dashboard. I write the following code :

create or replace function launch_generation()
returns trigger
as $$
declare
  json_post jsonb;
  json_header jsonb;
  request_id bigint;
begin
  if new.step_tunnel = 'Need_wait_prediction' then
    json_post := jsonb_build_object('version', '5fefgd3R***')
    || jsonb_build_object('input', jsonb_build_object('urls', new.picture_zip_link));
    json_header := jsonb_build_object('Authorization','Token r8_***');

    select net.http_post(
      url := 'https://api.replicate.com/v1/predictions',
      body := json_post,
      headers := json_header
    ) as request_id;

  end if;
  return new;
end;
$$ language plpgsql;

create trigger trigger_launch_generation
after update on public.customer_purchase
for each row
execute procedure launch_generation();

But when i make the change in my public.customer_purchase and this function is launch, i got always the same error in supabase :

[!warning] query has no destination for result data

I try to solve this, i read the pg_net documentation but that don't change...

Expected behavior

I just want the http post request succes.

Screenshots

This is the toast message i got went i change the value in my table for launch the trigger trigger_launch_generation :

Capture d’écran 2024-03-15 à 14 05 17

Additional context

Thanks for all people by advance he will help me with this bug ! ;)

Oksitaine commented 5 months ago

I correct the bug, i'm stupid x)

If someone have the same error, i made this change to the code bellow :

create or replace function launch_generation()
returns trigger
as $$
declare
  json_post jsonb;
  json_header jsonb;
  request_id bigint;
begin
  if new.step_tunnel = 'Need_wait_prediction' then
    json_post := jsonb_build_object('version', '5fefgd3R***')
    || jsonb_build_object('input', jsonb_build_object('urls', new.picture_zip_link));
    json_header := jsonb_build_object('Authorization','Token r8_***');

    select *
    into json_post
    net.http_post(
      url := 'https://api.replicate.com/v1/predictions',
      body := json_post,
      headers := json_header
    ) as request_id;

  end if;
  return new;
end;
$$ language plpgsql;

create trigger trigger_launch_generation
after update on public.customer_purchase
for each row
execute procedure launch_generation();