tags:

views:

4073

answers:

3

Is it possible in a sqlite database to craete a table that has a timestamp column that default to DATETIME('now') ?

Like this: CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, t TIMESTAMP DEFAULT DATETIME('now'));

This gives an error... How to resolve?

+11  A: 

i believe you can use

CREATE TABLE test (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  t TIMESTAMP
  DEFAULT CURRENT_TIMESTAMP
);

as of version 3.1 (source)

Owen
Helped me too, thank you! :)
codedevour
+6  A: 

according to dr. hipp in a recent list post:

CREATE TABLE whatever(
     ....
     timestamp DATE DEFAULT (datetime('now','localtime')),
     ...
);
rev
thanks - I was wondering how to create a default timestamp with local time rather than UTC
Plumo
A: 

It's just a syntax error, you need parenthesis: (DATETIME('now'))

If you look at the documentation, you'll note the parenthesis that is added around the 'expr' option in the syntax.

Adam Luter