So I have a function with is a filter call from my view user_information. The user_information contains a column with another function which generates the image url of a supabase.bucket.object, unless there is none..
Heres the codes:
generate_pfp function
DECLARE
profile_picture_id UUID;
profile_picture_name TEXT;
BEGIN
-- Fetch the profile picture ID using the given c_auth_id
SELECT coworker.profile_picture INTO profile_picture_id
FROM coworker
WHERE coworker.auth_id = c_auth_id;
-- Fetch the profile picture name using the profile picture ID
SELECT objects.name INTO profile_picture_name
FROM storage.objects
WHERE objects.id = profile_picture_id;
-- Return the complete URL, defaulting to 'default.png' if profile_picture_name is NULL
RETURN CONCAT('www.URL.com/', COALESCE(profile_picture_name, 'default.png'::text));
END;
user_information view
select
c.auth_id,
generate_short_display_name (c.auth_id) as display_name_short,
generate_full_display_name (c.auth_id) as display_name_long,
c.office_mail,
r.role_name,
generate_pfp(c.auth_id) as profile_picture_url,
c.personal_password_set
from
coworker c
left join coworker_roles r on c.role_id = r.id;
get user_info_from_uuid function
RETURNS JSON AS $$
DECLARE
result JSON;
BEGIN
SELECT json_build_object(
'auth_id', v.auth_id,
'display_name_short', v.display_name_short,
'display_name_long', v.display_name_long,
'office_mail', v.office_mail,
'role_name', v.role_name,
'profile_picture_url', v.profile_picture_url,
'personal_password_set', v.personal_password_set
) INTO result
FROM
view_coworker_informations v
WHERE
v.auth_id = c_auth_id;
RETURN result;
END;
Remember: The view contains the correct values, however the user_info_from_uuid does not, when calling from bash, but it also does output correct value when called in the integrated SQL CLI from Supabase.. this is confusing
Lönard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.