0
votes

After taking a crash course for SQLite3, I tried to make a db for my first project:

import sqlite3 as db

conn = db.connect('todo.db')
cursor = conn.cursor()

cursor.execute("CREATE TABLE todo(id serial primary key, title text, created 
timestamp default now(), done boolean default 'f')")

cursor.execute("INSERT INTO todo (title) VALUES('Learn web.py')")

Unfortunately I receive this error:

OperationalError: near "(": syntax error" at SQLite3

I do not understand what's wrong with the code. Can anyone explain what I am doing wrong?

1

1 Answers

0
votes

As shown in the documentation, if the default value is not a simple value, it must be enclosed in parentheses:

CREATE TABLE todo(
    ...,
    created timestamp default (now()),
    done boolean default 'f'
);

(And 'f' is not a valid value for a boolean. And now() is not an SQLite function.)