How do you set the default value of a date column to be "now" in UTC format? I think the answer involves the defaultValueComputed
attribute on the column element.
The documentation states:
defaultValueComputed A value that is returned from a function or procedure call. This attribute will contain the function to call.
What langauge is the function referred to supposed to be written in? Java? Is the function supposed to be the database vendor -specific date function I want to use? Is there any more documentation I can read on this topic?
How to set NOW () as default value for datetime datatype in MySQL? We can set the now () function as a default value with the help of dynamic default. First, we will create a table with data type” datetime”. After that, we will set now () as the default value for column “MyTime” as shown below.
take only aware datetime.datetime , return only aware datetime.datetime , never take or return naive datetime.datetime , ensure timestamps in database always to be encoded in UTC, and work as you’d expect. Note that for server_default=func.now () and func.now () to work :
As of MySQL 5.6.5, you can use the DATETIME type with a dynamic default value: CREATE TABLE foo (creation_time DATETIME DEFAULT CURRENT_TIMESTAMP, modification_time DATETIME ON UPDATE CURRENT_TIMESTAMP) Or even combine both rules: modification_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
I have two columns in table users namely registerDate and lastVisitDate which consist of datetime data type. I would like to do the following. Set lastVisitDate default value to 0000-00-00 00:00:00 Instead of null which it uses by default.
Maybe this topic in the liquibase forum will help?
I think defaultValueComputed
will take a database specific function to express "now". In mySQL it would be CURRENT_TIMESTAMP
so it could look like this:
<createTable tableName="D_UserSession"> <column name="ts" type="TIMESTAMP" defaultValueComputed="CURRENT_TIMESTAMP"/> </createTable>
(Copied from the forum post.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With