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.

Comments

  1. This is a well-researched article which you have shared here about sqlite. This is a very informative and useful article. This type of advice is not easy to find so, thanks for this information. Oracle fusion scm training

    ReplyDelete

Post a Comment

Popular posts from this blog

2 ways to get SQLite to put dates into columns

BootstrapX clickover

What's installed on my ec2