tags:

views:

84

answers:

3

I have a timestamp in a mysql table with attribute "ON UPDATE CURRENT_TIMESTAMP". Is there a way to manually disable updating the timestamp on a special occasion? (eg: updating the entry to revise a blog post, but not to re-date it)

+2  A: 

don't use timestamps, but track times manually.

if you really want to update a record and don't update it's timestamp use:

UPDATE `table` SET `timestamp` = `timestamp`, `col` = 'new data' …;
knittl
+2  A: 

You can manually set the value of the column to its current value in the update command:

UPDATE table SET x=y, timestampColumn=timestampColumn WHERE a=b;

If you don't set the value in the query, it will be updated to the current timestamp as per the table definition.

Andy
+2  A: 

Is there a way to manually disable updating the timestamp on a special occasion? (eg: updating the entry to revise a blog post, but not to re-date it)

Sounds like you need to configure the default constraint so that it populates the column on insertion only:

DEFAULT CURRENT_TIMESTAMP

Changing it to only be this means that any revisions will not trigger the timestamp value to be updated. IE: If you created the blogpost yesterday, and corrected a typo today - the date in the column would still be for yesterday.

OMG Ponies
Perfect, thank you!
Yongho