Jakub Szlaur
Jakub Szlaur

Reputation: 2132

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

What DB I am using?

What do I need?

How can I update automatically a timestamp?

Upvotes: 4

Views: 9062

Answers (1)

Jakub Szlaur
Jakub Szlaur

Reputation: 2132

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.

Upvotes: 11

Related Questions