How to update "updated_at" column automaticly when related row is updated?

Hello.

I'm using PostgreSQL as a dbms. So driver is pg. I want to update the "updated_at" column when the row is updated.

Is this implementation is ok for the feature.

const updated_at = timestamp("updated_at")
  .notNull()
  .defaultNow()
  .$onUpdateFn(() => sql`now()`);
Was this page helpful?