Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supabase: How to automatically update a timestamp field after updating a row?

What DB I am using?

  • Supabase hosted version

What do I need?

  • After I update a row with .update({ name: 'Middle Earth' }) method I need to automatically update also a timestamp in my table.

How can I update automatically a timestamp?

like image 572
Jakub Szlaur Avatar asked Oct 22 '25 11:10

Jakub Szlaur


1 Answers

1)If you already have a table use this script (provided by Supabase devs themselves):

create extension if not exists moddatetime schema extensions;

-- assuming the table name is "todos", and a timestamp column "updated_at"
-- this trigger will set the "updated_at" column to the current timestamp for every update
create trigger handle_updated_at before update on todos
  for each row execute procedure moddatetime (updated_at);

2)What if I don't wanna use the moddatetime extension?

This stackoverflow question will give you an answer.

like image 146
Jakub Szlaur Avatar answered Oct 25 '25 20:10

Jakub Szlaur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!