© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago
Subesz

RPC to duplicate a row with relations

I'm trying to create an RPC I can call to duplicate a row in my database while duplicating the relations aswell.
Here is a dbfiddle where you can see where I'm at currently. (This functionality is basically just to have a week of exercises that you can copy again so you don't have to add everything again manually)

https://dbfiddle.uk/_egziGjL

It is working exactly how I want it except I can't figure out how to create new copies of the suggested_loads linked on the exercise_sets table.

I only have basic knowledge of SQL and while I could make a series of queries, basically a query for each day and exercise, it would take a long time and I want to do it faster. ( Tried it before, took a lot longer than I would wait for an app to load ).

Based on the dbfiddle the expected result at the end would be to have load_id 1 in the first row and load_id 2 in the middle where the new week is added.
Postgres 13
 status
CREATE TABLE
 status
CREATE TABLE


 status
CREATE TABLE
 status
CREATE TABLE


 status
CREATE TABLE
 status
CREATE TABLE


 status
CREATE TABLE
 status
CREATE TABLE


 status
CREATE TABLE
 status
CREATE TABLE


 status
CREATE TABLE
 status
CREATE TABLE


 status
INSERT 0 3
 status
INSERT 0 3


 status
INSERT 0 2
 status
INSERT 0 2


 status
INSERT 0 4
 status
INSERT 0 4


 status
INSERT 0 4
 status
INSERT 0 4


```...
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

Updating many2many relations with RPC call
SupabaseSSupabase / help-and-questions
4y ago
How to return table row on RPC function?
SupabaseSSupabase / help-and-questions
3y ago
Relations with id array
SupabaseSSupabase / help-and-questions
4y ago
Upsert a specific row with API
SupabaseSSupabase / help-and-questions
4y ago