Hello everyone! I was wondering what is the best w...
# help
h
Hello everyone! I was wondering what is the best way possible today for executing different writes from an action?, a transaction-like process. To be more specific, when I create a user (auth), I want to create a row linked to this user in different tables in public database (ex. wallet, profile, etc). I was thinking about create a trigger, which calls a function, that function will handle the insert in different tables and it would work. But I was thinking... what if some of these inserts fails for any reason, will I end up with inconsistent data? with partial inserts or any thing like that?, if so... there's any way to avoid that risk? thanks a lot in advance
n
Hello @Haus Of Alejandro! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
I assume you are doing something like this: https://supabase.com/docs/guides/auth/managing-user-data#advanced-techniques If either the insert fails on the main table or your trigger function errors then the entire operation fails... based on observation and from the Postgres manual:
Copy code
The return value of a row-level trigger fired AFTER or a statement-level trigger fired BEFORE or AFTER is always ignored; it might as well be null. However, any of these types of triggers might still abort the entire operation by raising an error.
h
@garyaustin yes, exactly, almost the same scenario as the example provided, but with a couple of additional inserts on different tables involved in the function triggered. But I didn't knew that it behaves like a transaction already. Thank you so much!
n
Thread was archived by @Haus Of Alejandro. Anyone can send a message to unarchive it.