Supabase:如何在更新行后自动更新时间戳字段?

Jak*_*aur 4 postgresql supabase supabase-database

我正在使用什么数据库?

  • Supabase 托管版本

我需要什么?

  • 使用方法更新行后,.update({ name: 'Middle Earth' })我还需要自动更新表中的时间戳。

如何自动更新时间戳?

Jak*_*aur 8

1)如果您已经有一个表,请使用脚本(由 Supabase 开发人员自己提供):

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);
Run Code Online (Sandbox Code Playgroud)

2)如果我不想使用moddatetime扩展程序怎么办?

这个stackoverflow 问题会给你答案。