Gabor Szabo <[EMAIL PROTECTED]> writes:
> Is it possible to set datetime('now') as the default value of a field ?
>
> sqlite-2.8.15.bin, I tried this but it gave me an error message:
>
> sqlite> create table b (r DATE DEFAULT datetime('now'));
> SQL error: near "(": syntax error
>
> Is there some other way to achive this ?
Something like this should work:
% sqlite :memory:
SQLite version 2.8.16
Enter ".help" for instructions
sqlite> CREATE TABLE test_table (a INTEGER, timestamp DATE);
sqlite> CREATE TRIGGER test_table_insert_tr
...> AFTER INSERT
...> ON test_table
...> FOR EACH ROW
...> BEGIN
...> UPDATE test_table
...> SET timestamp = datetime('now');
...> END;
sqlite>
sqlite> INSERT INTO test_table (a) VALUES (23);
sqlite> .mode line
sqlite> SELECT * FROM test_table;
a = 23
timestamp = 2005-05-05 12:45:39
sqlite>