# How to retrieve integer value from SQLite for display and comparison

**URL:** <https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180>\
**Category:** General\
**Created:** [3 April 2020 20:12 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180 "2020-04-03T20:12:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![teladia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teladia/32/19345_2.png) [@teladia](https://discourse.nodered.org/u/teladia)\
**Post date:** [3 April 2020 20:12 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/1 "2020-04-03T20:12:55Z")

</div>

Good Day, I am new to the node red environment. The project at hand is a Smart Vending machine which is for my final year project. I have managed to get a bit done on my own by reading up and using advice from the forums. Currently I am struggling to correctly read data from my DB in order to display and use those values in other functions.

 ![2020-04-03-215409_1920x1080_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/12057d85829ab5122f67a08548dcc67360f01814.png)

As you can see above I have a table populated with data , I require to retrieve the INT values from the Price column but when I do that I receive a the full payload object as "[{ Price: 20 }]" , i tried using the split function but best I got out was "20}]" but in a string format.

The topic request to the DB is " select Price from DB where ID == 1" which is working but as stated above its not returning just the INT value as required. Also i would like to store this value and compare it to the monetary amount the user will be required to insert into the machine.

I have tried everything with my given abilities to no avail, any help or recommendations would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2020 20:24 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/2 "2020-04-03T20:24:26Z")

</div>

Read the section [Working with messages](https://nodered.org/docs/user-guide/messages).

You don't split the values, that string you showed is JSON - use the JSON node to convert the JSON to a JS object then simply access `msg.payload[0].Price`

Trust me, spend 10 mins in that section of the very helpful extensive documentation - it will teach you about these things.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 April 2020 20:37 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/3 "2020-04-03T20:37:41Z")

</div>

I don't think the sqlite node should return a string `"[{ Price: 20 }]"`, I would have expected it to return the array itself `[{ Price: 20 }]`. If you feed it into a debug node you will see whether it is a string or an array. If it is already an array then you won't need the JSON node to convert it from string to array.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2020 20:42 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/4 "2020-04-03T20:42:24Z")

</div>

I thought the same but the OP said he managed to split it but gets "20}]"

Partly the reason I pointed the OP to the docs so he learns how to inspect the messages 👍

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 April 2020 21:08 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/5 "2020-04-03T21:08:32Z")

</div>

> [@Steve-Mcl](#):
>
> the OP said he managed to split it but gets "20}]"

Good point  
@teladia is that string coming straight out of the sqlite node? If so which have you installed node-red-node-sqlite or one of the other sqlite nodes?

---

<div class="post-metadata">

**Author:** ![teladia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teladia/32/19345_2.png) [@teladia](https://discourse.nodered.org/u/teladia)\
**Post date:** [4 April 2020 17:09 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/6 "2020-04-04T17:09:03Z")

</div>

Hi Steve

Thanks for the feedback, I did give that a read and it definitely gave me a better understanding of the messages and its properties.

Yes I forgot to mention that it was passed through a JSON node before going into the split node. I have tried the above with and without using the JSON node before feeding into my function. I am however receiving the following error : "Function tried to send a message of type number"

From that error I take it that the function is actually just receiving the INT value of 20 but doesn't like that. Could you please explain why that is , or am I going about it wrongly?

---

<div class="post-metadata">

**Author:** ![teladia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teladia/32/19345_2.png) [@teladia](https://discourse.nodered.org/u/teladia)\
**Post date:** [4 April 2020 17:10 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/7 "2020-04-04T17:10:53Z")

</div>

Hi Colin

Sorry for that, as I stated to Steve I forgot to mention that I passed the data through a JSON node first , so that would explain the msg received. The SQLite is the original and does pass the proper object through. Thanks!

---

<div class="post-metadata">

**Author:** ![teladia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/teladia/32/19345_2.png) [@teladia](https://discourse.nodered.org/u/teladia)\
**Post date:** [4 April 2020 17:34 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/8 "2020-04-04T17:34:32Z")

</div>

Hi Steve

I managed to used a change node to get the INT value straight out and store it as a flow by using the msg.payload[0].Price as you stated.  
I will continue to see if I can create a function to compare that value against the users input amount.  
Thanks

---

<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:** [18 April 2020 17:34 UTC](https://discourse.nodered.org/t/how-to-retrieve-integer-value-from-sqlite-for-display-and-comparison/24180/9 "2020-04-18T17:34:40Z")

</div>

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