automatic modified timestamp

736 views
Skip to first unread message

Jukka-Pekka Rahkonen

unread,
May 21, 2012, 5:38:56 AM5/21/12
to h2-da...@googlegroups.com
Hello,
Is there a way to create automatically updating last modified timestamp field. It is done in mysql like this:
create table test (
  modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  name VARCHAR(20)
);

How to do this in H2?

This does not work: 
"TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE SET DEFAULT"
it translates to:
"TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON[*] UPDATE SET DEFAULT"
and it fails.



Noel Grandin

unread,
May 21, 2012, 11:51:20 AM5/21/12
to h2-da...@googlegroups.com, Jukka-Pekka Rahkonen
you need a trigger.
http://www.h2database.com/html/features.html#triggers
> --
> You received this message because you are subscribed to the Google
> Groups "H2 Database" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/h2-database/-/wevHeKkPbIgJ.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.

Rami Ojares

unread,
May 21, 2012, 11:55:55 AM5/21/12
to h2-da...@googlegroups.com
Try
create table test (
modified TIMESTAMP AS CURRENT_TIMESTAMP(),
name VARCHAR(20)
);

- Rami
Reply all
Reply to author
Forward
0 new messages