Wednesday, March 11, 2009

Easiest way to get SQLite to put in timestamps

After doing some more digging (must have been blind before), I found that SQLite supports a default timestamp at insert.

Here is an example of a create statement using the default with SQLite CURRENT_TIMESTAMP keyword.
create table user (
id integer primary key,
username text not null,
password text not null,
first_name text,
last_name text,
created text default CURRENT_TIMESTAMP
UNIQUE(username)
);
That is much easier that my previous attempt. Not sure how I missed it. But it doesn't solve the missing now() function for updates. ( did find a language solution for that in Perl but that is for another post). In that case, it will still require the use of datetime('now').

Reference: SQLite CREATE TABLE reference.

1 comment:

  1. Hi,
    I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article. Oracle Financials training
    Thank you/.

    ReplyDelete