Andreas Dolk
Andreas Dolk

Reputation: 114767

Change default value for column on h2 database to current timestamp

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.

Upvotes: 8

Views: 20370

Answers (1)

sgeddes
sgeddes

Reputation: 62841

Looks close, have you tried:

ALTER TABLE <table name> ALTER COLUMN <column name> SET DEFAULT CURRENT_TIMESTAMP

Upvotes: 12

Related Questions