Node-red Sqlite SELECT syntax error

Hi all.

I'm getting an error in a SELECT command from Sqlite DB.
The error msg is : "Error: SQLITE_ERROR: near "Index": syntax error"

The command I output to Sqlite DB:
var newMsg = {
// "topic": "SELECT * FROM MonthKwh ORDER BY Index DESC LIMIT 100"} *)
"topic": "SELECT * FROM MonthKwh ORDER BY Index DESC LIMIT 1"}
//"topic": "SELECT Month FROM MonthKwh"}
return newMsg;

The TABLE MonthKwh structure is:

CREATE TABLE MonthKwh (
Index INTEGER PRIMARY KEY AUTOINCREMENT,
Year INTEGER,
Month INTEGER,
XKwh REAL,
FKwh REAL
);

What I'm trying to do:
If the last row is in the same actual month, I want to overwrite this last row.
If the actual month is not the same of last row, then I need to INSERT a new row.

Thanks in advance.

Pau Torras

Go take a look at this and then see if you understand your issue.

Thanks @zenofmud,

With the information provided, I see the problem is the name field of the column Index.
ÂżIsn't it?

Thanks

That's what the error message was telling you. Basically never use reserved words for column names :wink:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.