© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
12 replies
zackderose

Returning usage in stored function

Creating a stored procedure to call via supabase client's rpc method.

My sql:

create function create_new_post("userId" uuid, "title" text, "content" text)
    returns boolean
    language plpgsql
    as $$
    begin
          with "insertedPost" as (
            insert into posts ("user_id", "path") values ($1, 'root')
            returning "id"
          )
          insert into post_contents
            ("post_id", "title", "content") values
            ((select "id" from "insertedPost"), $2, $3);
          insert into post_score
            ("post_id", "score") values
            ((select "id" from "insertedPost"), 0);
        commit;
        return true;
    end; $$
create function create_new_post("userId" uuid, "title" text, "content" text)
    returns boolean
    language plpgsql
    as $$
    begin
          with "insertedPost" as (
            insert into posts ("user_id", "path") values ($1, 'root')
            returning "id"
          )
          insert into post_contents
            ("post_id", "title", "content") values
            ((select "id" from "insertedPost"), $2, $3);
          insert into post_score
            ("post_id", "score") values
            ((select "id" from "insertedPost"), 0);
        commit;
        return true;
    end; $$

When I call the rpc from the supabse client, I'm getting the error "Relation "insertedPost" does not exist".

Can anyone see what I'm doing wrong here?
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 returning JSON
SupabaseSSupabase / help-and-questions
3y ago
Solved - Invoke edge function returning buffer-blob
SupabaseSSupabase / help-and-questions
4y ago
Edge Function returning 500 when querying table (Supabase)
SupabaseSSupabase / help-and-questions
8h ago
PostgrestError is imported ... but never used & FunctionRegion, FunctionsError, ... are imported ...
SupabaseSSupabase / help-and-questions
3w ago