So I'm kind of new to databases in general, or at least not very experienced.
But in general I think I kind of understand how it all works.
So I had a trigger function to add row to a profile table when a new user signs up, it was all working as expected when I only was adding the user ID and the username, but then I decided to add an svg to the avatar and I just can't figure out what I am doing wrong.
This is my function:
declare
svg text;
begin
select content
into svg
from http_get(concat('https://avatars.dicebear.com/api/bottts/', new.id::text, '.svg'));
insert into public.profile (id, username, avatar)
values (
new.id,
new.raw_user_meta_data ->> 'name',
svg
);
return new;
end;
I've done a lot of trial and error and if I remove the http_get and just insert a string into avatar like so and it works:
declare
svg text;
begin
svg := 'this works...';
insert into public.profile (id, username, avatar)
values (
new.id,
new.raw_user_meta_data ->> 'name',
svg
);
return new;
end;
and I've also tried to export the http_call into an external function:
declare
svg text;
begin
select content
into svg
from http_get(concat('https://avatars.dicebear.com/api/bottts/', seed, '.svg'));
return svg
end;
And call it, and it does return the svg html code as text as I would expect it to.
But then I add that function to the previous thing and it doesn't work:
insert into public.profile (id, username, avatar)
values (
new.id,
new.raw_user_meta_data ->> 'name',
get_dicebears_svg(new.id::text);
);
return new;
end;
I've also tried using cast(new.id as text)
instead of new.id::text
.
Could someone tell me what I am doing wrong?