grafana-sqlite-datasource icon indicating copy to clipboard operation
grafana-sqlite-datasource copied to clipboard

Getting unsigned int result for signed int

Open FroggyCorp opened this issue 1 year ago • 1 comments

Hi,

I use the 3.5.0 sqlite plugin with grafana enterprise rpi 9.3.6 I have some temperature time series. I use the following query :

SELECT (timestamp * 1000) as datetime, cast(value as INT) as temperature FROM sensors WHERE timestamp >= $__from / 1000 and timestamp < $__to / 1000 and source_id = 20 and sensor_id = 1 and type = 101 ORDER BY timestamp ASC

12.34°C is stored as 1234 so value = temperature * 100

What i get, is unsigned result as for negative value i have :

2024-01-14 09:39:17 65443 2024-01-14 09:49:19 65486 2024-01-14 10:01:10 31 2024-01-14 10:12:52 11

On the query inspector, i get the same result, but with a SQLite browser, i have negative value from the SQLite.file, as SQLite store integer as signed by default. I tryed some "cast" but with no effect. I come here with that problem, but in fact i don't really know if its coming from sqlite plugin or grafana which should convert unsigned to signed on query.

If it's not plugin releavant, i apologize

thx in advance for any help.


Did not mention it, but i already tryed with : SELECT (timestamp * 1000) as datetime, value as temperature FROM sensors WHERE timestamp >= $__from / 1000 and timestamp < $__to / 1000 and source_id = 20 and sensor_id = 1 and type = 101 ORDER BY timestamp ASC

FroggyCorp avatar Apr 01 '24 15:04 FroggyCorp

Could you provide a CTE that does not work? Something in the shape of this

with data(time, text, city) AS (VALUES
    (724125600, 'annotation London', 'London'),
    (724161600, 'annotation New York', 'New York'),
    (724197600, 'annotation Washington', 'Washington')
) SELECT * from data

fr-ser avatar Apr 07 '24 05:04 fr-ser

Hi, After getting more into it, it was my mistake. In fact it was TEXT and not INTEGER for "value" row and i get a bug when i save value. For reason i dont get, sometimes i got negative value and sometimes not, it why i thought it was lib problem, but it was only my code. I apologize

FroggyCorp avatar Apr 11 '24 10:04 FroggyCorp