Database function returning JSON

Hello, I am using Supabase Swift SDK and trying to call a database function that returns a JSON.

When I call the function, I get an issue saying relation "quizzes" does not exist

Here is the SQL code in the function
DECLARE
    result JSON;
BEGIN
    SELECT json_agg(json_build_object(
        'id', qz.id,
        'createdAt', qz.created_at,
        'quizName', qz.quiz_name,
        'quizDescription', qz.quiz_description,
        'userId', qz.user_id,
        'questions', (SELECT json_agg(json_build_object(
            'id', qs.id,
            'quizId', qs.quiz_id,
            'question', qs.question,
            'answer', qs.answer,
            'createdAt', qs.created_at
        )) FROM Questions qs WHERE qs.quiz_id = qz.id)
    )) INTO result
    FROM Quizzes qz;

    RETURN result;
END;


I also attached the struture of my tables.
Was this page helpful?