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; $$

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?
Was this page helpful?