© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
8 replies
jasondubon

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
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;
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.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Database Function or Edge Function?
SupabaseSSupabase / help-and-questions
4y ago
deploy database function
SupabaseSSupabase / help-and-questions
13mo ago
Database insert returning 404 (TypeScript)
SupabaseSSupabase / help-and-questions
14mo ago
Returning usage in stored function
SupabaseSSupabase / help-and-questions
4y ago