Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top