0
I have the following table:
Create Table tb_teste(
cod_key integer not null,
data_cad timestamp not null default now(),
data_atualizacao timestamp not null default now(),
primary key(cod_key)
)
In Mysql I have the option "... ON UPDATE CURRENT_TIMESTAMP"
I would like the "data_update" field to have the date and times updated whenever there is an update in the table.
In Postgres you have this option or I need to do Triggers/Function?
Forgive my ignorance but
ON UPDATE
doesn’t apply to foreign keys? I could not find such an option in the SQL manual and also checked in the Postgresql manual and found nothing similar.– anonimo
So Mysql has an option to create the table with an ON UPDATE in timestamp fields... by default every time the table about any change it updates with the current date and time value... is a very interesting function of Mysql, I thought it had something like this in Postgresql, but I’ve been reading the manual and I didn’t find no, only with triggers same.
– Marcelo
Interesting the Mysql manual does not mention this option when explaining CREATE TABLE but only when explaining TIMESTAMP.
– anonimo
https://stackoverflow.com/questions/1035980/update-timestamp-when-row-is-updated-in-postgresql
– Cristiano
It is... you declare it like this: CAMPO_DATA TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, It is very practical
– Marcelo