# Node-red Sqlite SELECT syntax error

**URL:** <https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838>\
**Category:** General\
**Created:** [9 March 2020 09:36 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838 "2020-03-09T09:36:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)\
**Post date:** [9 March 2020 09:36 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838/1 "2020-03-09T09:36:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 March 2020 10:07 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838/2 "2020-03-09T10:07:08Z")

</div>

Go take a [look at this](https://www.sqlite.org/lang_keywords.html) and then see if you understand your issue.

---

<div class="post-metadata">

**Author:** ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)\
**Post date:** [9 March 2020 13:05 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838/3 "2020-03-09T13:05:18Z")

</div>

Thanks @zenofmud,

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

Thanks

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 March 2020 15:15 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838/4 "2020-03-09T15:15:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 March 2020 15:15 UTC](https://discourse.nodered.org/t/node-red-sqlite-select-syntax-error/22838/5 "2020-03-23T15:15:37Z")

</div>

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