Sqlite3.OperationalError: next to "X": syntax error

This code:

conn = connect('emails.db')
curs = conn.cursor()

curs.execute('''create table items
  (integer primary key, X, Y)''')

curs.execute("INSERT INTO items (integer primary key, X, Y) VALUES ('today', 'X', 'Y')")

connection.commit()

returns:

sqlite3.OperationalError: next to "primary": syntax error

How did it happen? I do not see what I am doing wrong. The values ​​I put in are all the btw variables.

+5
source share
1 answer

Your CREATE TABLE is incorrect: it does not specify a name for the first column (integer primary key). SQLite now believes that the field is named integer and does not have a specific data type. You probably wanted to have an INTEGER PRIMARY KEY field because it is very efficient. To do this, follow the CREATE TABLE syntax and give it a name:

CREATE TABLE items
( id INTEGER PRIMARY KEY
, x  DOUBLE
, y  DOUBLE
);

: X Y , , . , , . , , , INTEGER. - , , .

, INSERT ( ), SQLite - .

, , , , "" ( ) ?!?


:, , X Y , SQL:

curs.execute("INSERT INTO items (X, Y) VALUES (:X, :Y)", {X: X, Y: Y})

id, SQLite , . , . , , !

:X :Y SQL X Y , execute.

, SQL.

+9

All Articles