Reputation: 7120
I am trying to have a column holding the timestamp value whose default value is today + a few days
. Could this be done during table creation time?
Upvotes: 5
Views: 2322
Reputation:
Yes it can be done as in the following example:
sqlite> create table foo (i int, j text default (datetime('now', '+5 days')));
sqlite> insert into foo (i) values (1);
sqlite> select * from foo;
1|2012-04-11 07:49:04
sqlite> insert into foo (i) values (2);
sqlite> select * from foo;
1|2012-04-11 07:49:04
2|2012-04-11 07:49:14
If you only want to store the date part, use date
instead of datetime
. Here I use datetime
to show that the default expression is evaluated when inserting in the table, not when the table is created.
Upvotes: 3