Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default value for column on h2 database to current timestamp

Tags:

java

sql

h2

I have a h2 database with a schema that is auto generated via JPA/hibernate. Now I want to alter a not-null timestamp type column on the database to default to the current time.

I actually use a trigger, and that works, but I'd like to know if there's a more elegant way to achieve this, something like (the following snippet doesn't work)

ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT CURRENT_TIMESTAMP;

I looked at the documentation and tried some variants of the above "pseudo statement" but with now success.

like image 599
Andreas Dolk Avatar asked Jan 08 '13 14:01

Andreas Dolk


1 Answers

Looks close, have you tried:

ALTER TABLE <table name> ALTER COLUMN <column name> SET DEFAULT CURRENT_TIMESTAMP
like image 105
sgeddes Avatar answered Sep 30 '22 04:09

sgeddes