Search code examples
node-sqlite3sql-returning

SQLite Syntax Error near "RETURNING" (Node)


I got a Node script with an Express server, im trying to insert a new entry into a Table. If got folloing setup:

db.run('CREATE TABLE lists(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)');
...
db.get(`INSERT INTO lists (name) VALUES (?) RETURNING *;`, [name], (err, row) => {
        ...
    });

And the Insert statement throws:

Error: SQLITE_ERROR: near "RETURNING": syntax error
--> in Database#get('INSERT INTO lists (name) VALUES (?) RETURNING *;', [ 'Testing' ], [Function (anonymous)])

but this should be working according to the sqlite wiki

any advise?


Solution

    • Support for the RETURNING clause was added in Sqlite 3.35.

    • While you have Sqlite 3.36 installed in your operating system's environment, it seems your Node environment has an older version of the sqlite3 npm package which has Sqlite 3.34.

    • On GitHub, as of early November 2021, the sqlite3 package version 5.0.2 for npm was released in February 2021 with an older version of Sqlite.