© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
81 replies
TARS

RPC anon insert return ID

Hello,

In this project I'm using anonymous insert of data from the front-end (next.js) into supabase postgres. The problem with this is that I also need to return the auto incremented ID for the data to the anonymous user. For this to be possible with RLS I guess I need to make read available to anyone, which is a no no. It's bad enough that insert will be open to anyone.

As I understand it, I need to use RPC for this. The problem is that I don't really know how to think about the logic.

I created a database function and I guess it needs to start with something like this.

begin
insert into public.hosts (data)
return id
end
begin
insert into public.hosts (data)
return id
end


How do I make the logics here so that the id from the newly created row is returned? Thanks everyone. I'm slow but I'm learning.
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
Next page

Similar Threads

Enable insert for anon
SupabaseSSupabase / help-and-questions
14mo ago
Bulk Insert RPC to return inserted values.
SupabaseSSupabase / help-and-questions
4y ago
How to return id upon Insert()
SupabaseSSupabase / help-and-questions
4y ago
Return data on insert
SupabaseSSupabase / help-and-questions
4y ago