Database transactions #526
Replies: 52 comments 61 replies
-
Need Transactions, BEGIN / COMMIT / ROLLBACK cannot find it anywhere in the docs? |
Beta Was this translation helpful? Give feedback.
-
me too. I Do Need Transactions, BEGIN / COMMIT / ROLLBACK like: await supabase.transaction( supabase.from(...).update(...) When I ask the supabase.io tech team, I didn't get the solution for solving this problem and I only get suggest for using rpc. But I don't know how to really construct the rpc function for multiple database actions, including insert to the first table by multiple rows and then update the second table for different rows with different id and then update the third table for updating the data by key, if there is any error occurred during the THREE TABLEs transaction then ROLLBACK, otherwise COMMIT the transaction. Any solution or suggestion for writing the correct rpc function to handle the multiple tables' operations(insert, update, ...) in one transaction which can make sure the data consistency? Need help!! |
Beta Was this translation helpful? Give feedback.
-
I find firebase's transactions and batched writes APIs to be very useful and developer-friendly. It would be fantastic to see something similar integrated into supabase. As it stands, this is a huge sticking-point for me when deciding to use supabase vs alternatives. Learning and writing RPCs each time we want to do a simple batched write / atomic transaction is not fun. Firebase docs on transactions / batched writes: https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes Example of firebase batching API from their docs: import { writeBatch, doc } from "firebase/firestore";
// Get a new write batch
const batch = writeBatch(db);
// Set the value of 'NYC'
const nycRef = doc(db, "cities", "NYC");
batch.set(nycRef, {name: "New York City"});
// Update the population of 'SF'
const sfRef = doc(db, "cities", "SF");
batch.update(sfRef, {"population": 1000000});
// Delete the city 'LA'
const laRef = doc(db, "cities", "LA");
batch.delete(laRef);
// Commit the batch
await batch.commit(); Original comment on other thread: https://github.com/supabase/supabase-js/issues/87#issuecomment-999147766 |
Beta Was this translation helpful? Give feedback.
-
Supabase-cli is a step in the right direction in a CI/CD workflow but to suggest using RPC functions to get transactions is shamelessly trite. |
Beta Was this translation helpful? Give feedback.
-
Bumping this because it would be nice to have this as a feature instead of having postgres rpc functions that fire with no knowledge if it failed or not. |
Beta Was this translation helpful? Give feedback.
-
This makes me sad too. I hope the Supabase devs will prioritize this. Another strike against Supabase in seeing if I can use it in my production environment for my company. :( |
Beta Was this translation helpful? Give feedback.
-
Wanted to share a relatively new option to transactions in Supabase, and while this is not an ideal alternative to client transactions, it could be better in some ways than writing stored procedures: with release of Supabase Edge Functions - there is a way to connect to Postgres directly: https://supabase.com/docs/guides/functions/connect-to-postgres thus have access to transactions API. So instead of writing PL/pgSQL you can write JS/TS (or even Dart) and potentially reuse some of your code. |
Beta Was this translation helpful? Give feedback.
-
Just following up here with my two cents after using transactions via
I'd wonder if @steve-chavez and team have made progress on the hard problem of doing stateful transactions through a stateless API? |
Beta Was this translation helpful? Give feedback.
-
How is this not a priority feature? |
Beta Was this translation helpful? Give feedback.
-
Can we please make this feature happen, it's essential for backend development. Not sure why it hasn't been developed already? |
Beta Was this translation helpful? Give feedback.
-
hello supabase team, i hope you are doing well if supabase implements this feature, it will hands down be the only BaaS i'll use till i die! Thanks |
Beta Was this translation helpful? Give feedback.
-
Any update about this feature? |
Beta Was this translation helpful? Give feedback.
-
Hello... anyone here?.... This discussion has gone silent 😮💨 , is there an ETA for this feature?? Thanks for your hard work, we appreciate the effort that went into supabase. |
Beta Was this translation helpful? Give feedback.
-
In a need of transaction support too. |
Beta Was this translation helpful? Give feedback.
-
+1 👍 |
Beta Was this translation helpful? Give feedback.
-
I came here looking to see why supabase does not support database transactions... turns out there is not a good reason. might need to switch to firebase my use case demands that i use many transactions to prevent overwriting data and to make sure it all fails or or all succeeds. disappointed to see this has been a request for years |
Beta Was this translation helpful? Give feedback.
-
+1, hopefully we can get this soon. Are there any work arounds if we don't use postgREST? |
Beta Was this translation helpful? Give feedback.
-
any updates on transaction support? |
Beta Was this translation helpful? Give feedback.
-
It seems like this thread has devolved into a bunch of complaints around lack of support for transactions. The folks at Supabase are surely aware that this is a very desired feature and have provided the bandaid of support via functions (yes I'm aware this is hard to maintain and less than ideal), but: complaining and one word comments, gifs, and so on are just useless noise. I'm sure the feature is on their roadmap, or maybe there are technical roadblocks that would require too much work? I don't know, but this IS an open source platform. It seems like one path to figuring out how/if transactions can be added would be looking at what's missing from PostgREST, adding the functionality there and then integrating it into the various client libs. I'm not saying that's easy, or even possible, but instead of complaints and gifs, maybe we could all figure out ways to contribute to the project/community and work together to try and make this feature happen. |
Beta Was this translation helpful? Give feedback.
-
Supabase response
|
Beta Was this translation helpful? Give feedback.
-
RPC functions are fine but how do we get it locally inside of our code and with version control? That solves the issue |
Beta Was this translation helpful? Give feedback.
-
+1 |
Beta Was this translation helpful? Give feedback.
-
+1 Bottom line: Supabase needs support for transactions without having to use an RPC or Edge Function or whatever else.. |
Beta Was this translation helpful? Give feedback.
-
Welcome to the new year 2025! If anyone finds this looking for transaction support here is the latest info I could gather. Currently not supported. Currently not on the roadmap. There are several workarounds. You can encapsulate the logic in a Postgres SQL function then call it with rpc This issue is 4 years old. So make your comment asking for it, vote up the other posts you find useful or want to support etc. Did I miss anything? |
Beta Was this translation helpful? Give feedback.
-
Screeching coder noises.... |
Beta Was this translation helpful? Give feedback.
-
Update: we plan to support transactions. Follow issue PostgREST/postgrest#286 for the latest.
It would be handy if there was a way to execute multiple operations within a transaction. Similar to Ecto.Multi.
Maybe something like:
Would reduce the number of situations where a postgres function is needed.
Beta Was this translation helpful? Give feedback.
All reactions