0

I would like to create an SQLite table in python without the default rowid field.

For example, I have tried

import sqlite3

conn = sqlite3.connect("mydatabase.db")
cursor = conn.cursor()

sql = "CREATE TABLE tblTest (myid VARCHAR(20) PRIMARY KEY, testField1 VARCHAR(14), testField2 VARCHAR(2500) ) WITHOUT ROWID "

cursor.execute(sql)

And this is the error I get:

sqlite3.OperationalError: near "WITHOUT": syntax error

Any suggestions? Thank you in advance.

carmenism
  • 1,087
  • 3
  • 12
  • 31

1 Answers1

3

You probably need a newer version of SQLite. The without rowid syntax requires 3.8.2 or later.

Reference

The version of the sqlite library that's linked to the sqlite3 executable . . .

$ sqlite3 --version
3.7.9 2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e

The version that's incorporated into python's standard library . . .

$ python
[snip]
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.9'

For information about how version checking can mislead you, see this SO answer.

Community
  • 1
  • 1
Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
  • 1
    `version` [is not the version of the SQLite library](https://docs.python.org/2/library/sqlite3.html#sqlite3.version). – CL. Apr 03 '14 at 07:33