I want to insert data in case the ‘id’ doesn’t exist, and update it if the ‘id’ does exist AND the existing ‘timestamp’ is less than the new ‘timestamp’.
So far I haven’t figured out how to add this condition to an upsert. Please let me know if you have any pointers.
I know I could do 2 separate queries, an ‘insert try’ and then an update, but I would much rather get it done in 1 query.
Also, I am aware that I could do this with a raw sql statement, but I don’t know how to send this to supabase.
Thanks so much for the help!
2
Answers
this is the solution I came up with. Obviously not what I initially set out to do but works for now:
I ran into the same problem. I guess there is no elegant way achieve this. I also thought of raw SQL but it isn’t supported by supabase_flutter. What you’re trying to do is
conditional chaining
. In the supabase docs I found this example regarding the JavaScript API:You could do that similarly in Dart.
I hope this helps.