Re: Trigger

Поиск
Список
Период
Сортировка
От Erik Wienhold
Тема Re: Trigger
Дата
Msg-id ytjhuiiriv4f7j4jidsej2uuonfklccpozu2z4fzwcgsn2vniz@tgmttjb47bap
обсуждение исходный текст
Ответ на Re: Trigger  (Thiemo Kellner <thiemo@gelassene-pferde.biz>)
Список pgsql-admin
On 2024-04-03 16:42 +0200, Thiemo Kellner wrote:
> Am 03.04.2024 um 12:30 schrieb Rajesh Kumar:
> > I have one table with lot of columns (all vehicle details) and also have
> > updated_at column. Everytime there is a change in data, I want to backup
> > the original data into a new table?
> > 
> > What's the best option? A function and trigger before update?
> 
> I would say so.

An AFTER trigger is better suited for that because it runs after
constraints are checked and the UPDATE has completed.  This avoids
unnecessary inserts into the audit table in case the UPDATE fails.

The docs have examples on table auditing[1].

[1] https://www.postgresql.org/docs/current/plpgsql-trigger.html#PLPGSQL-TRIGGER-AUDIT-EXAMPLE

-- 
Erik



В списке pgsql-admin по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: About Autovacuum Query
Следующее
От: jaya kumar
Дата:
Сообщение: Re: About Autovacuum Query